Getting the route name inside a service in symfony

Viewed 623

guys so I have a service in which i have a constructor that accepts router service.

My question is how can I know the current route name?

This is my service:

class Navigation
{
    protected $modules;

    protected $router;

    public function __construct($modules, $router)
    {
        $this->modules = $modules;
        $this->router = $router;
    }
}

Thanks.

2 Answers

Or if your class is an AbstractController you can directly use this without further dependency injection:

$this->container->get('request_stack')->getCurrentRequest()->get('_route')
Related