IlyaDoroshin IlyaDoroshin - 7 months ago 7
PHP Question

How to get current route in Symfony 2?

How do I get the current route in Symfony 2?

For example,

routing.yml
:

somePage:
pattern: /page/
defaults: { _controller: "AcmeBundle:Test:index" }


How can I get this
somePage
value?

Answer

From something that is ContainerAware (like a controller):

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