0
votes

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?

1

1 Answers

0
votes

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