phpsymfonyroutessymfony-routing

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?


Solution

  • From something that is ContainerAware (like a controller):

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