urlsymfonybase-url

Getting the base url of the website and globally passing it to twig in Symfony 2


I'm making the switch from CodeIgniter to Symfony 2. Can someone please give me an example of how to:


Solution

  • Why do you need to get this root url ? Can't you generate directly absolute URL's ?

    {{ url('_demo_hello', { 'name': 'Thomas' }) }}
    

    This Twig code will generate the full http:// url to the _demo_hello route.

    In fact, getting the base url of the website is only getting the full url of the homepage route :

    {{ url('homepage') }}
    

    (homepage, or whatever you call it in your routing file).