0

I'm new to symfony so hopefully this is trivial How to get current route in Symfony 2? does not work for me because it returns route of the current controller

i have root controller that calls twig template in which another controller is being created with render url('_internal_main_navigation') and if i call

$request = $this->container->get('request');
$routeName = $request->get('_route');

from the nested controller i get _internal_main_navigation not _home or whatever is the root route

how would i get the _home?

Community
  • 1
  • 1
Martin
  • 1,752
  • 2
  • 13
  • 21

1 Answers1

0

turns out How to get current route in Symfony 2? had the answer, just not the accepted one

https://stackoverflow.com/a/11660777/711072 pointed me in the right direction

the trick is passing it through template to controller like

{% render url('_internal_main_navigation', { 'route': app.request.attributes.get('_route') }) %}

and then it can be accessed in controller like

$this->getRequest()->query->get('route');

in controller

Community
  • 1
  • 1
Martin
  • 1,752
  • 2
  • 13
  • 21
  • you want to redirect to home page from twig template right – Venkat.R Jan 08 '16 at 09:03
  • 1
    *i don't know how to link answers sorry for revision link* you have to click on or copy the **share** link below any answer. – A.L Jan 09 '16 at 14:34