Skip to content

Instantly share code, notes, and snippets.

@redleafar
Created November 19, 2016 21:37
Show Gist options
  • Save redleafar/5bcd597cd190c454583e17020011c50c to your computer and use it in GitHub Desktop.
Save redleafar/5bcd597cd190c454583e17020011c50c to your computer and use it in GitHub Desktop.
Inject current route in custom class (Symfony 2.8)

Use request_stack, for instance:

services:
    app.service:
        class: AppBundle\Class
        arguments: ["@request_stack"]

And in the class:

function __construct(\Symfony\Component\HttpFoundation\RequestStack $requestStack) {
		$request = $requestStack->getCurrentRequest();		
		$route = $request->attributes->get('_route');
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment