You can use the templating.helper.assets service. First define your assets base URL : # app/config/config.yml framework: templating: assets_base_url: "http://www.mywebsite.com/" Then just call the service from within your controller, command or wherever you are : <?php // src/Acme/Bundle/DemoBundle/Controller/DemoController.php namespace Acme\Bundle\DemoBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class DemoController extends Controller { public function indexAction() { $myAssetUrl = $this ->get('templating.helper.assets') ->getUrl('bundles/acmedemo/js/main.js', $packageName = null) ; // $myAssetUrl is "http://www.mywebsite.com/bundles/acmedemo/js/main.js" return array(); } }
Created
September 14, 2015 12:30
-
-
Save cagataycali/1e2aa3ef9fbb202c4a3a to your computer and use it in GitHub Desktop.
Asset url handling in controller From http://stackoverflow.com/questions/8811251/how-to-get-the-full-url-for-an-asset-in-controller
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment