How to get current route in Symfony 2?

IlyaDoroshin picture IlyaDoroshin · Aug 17, 2011 · Viewed 197.2k times · Source

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

tuxedo25 picture tuxedo25 · Aug 17, 2011

From something that is ContainerAware (like a controller):

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