Friday 15 July 2011

symfony - Symfony2 Assetic get asset urls from inside controller, not template -


I want to include the URL in one of the assets in my bundle, not in the template.

More specifically, but not very important: I am making a high chart chart using the OHHIHHRHR bundle, and I have to create some specific mark in some points of the graph that I am producing. That's why I need a URL, which is in the asset folder of my bundle.

Is it possible for the controller to call any asset manager and this user can be right in this asset?

You can call ($ packageName is optional):

  $ This- & gt; Container-> Receive ('assets.packages') - & gt; GetUrl ($ path, $ packageName);   

The old Symphony version is called templating.helper.assets for the service, so you use it:

  $ This- & gt; Container-> Get ('templating.helper.assets') - & gt; GetUrl ($ path, $ packageName);   

This is used in the same way as a twig function (in fact it is called in the twig function).

No comments:

Post a Comment