Skip to content
This repository

[FrameworkBundle] Controller forward does not set route #854

vlechemin opened this Issue May 09, 2011 · 6 comments

4 participants

Vincent Lechemin Fabien Potencier Christophe Coevoet Maël Nison
Vincent Lechemin

Once inside a controller, $this->forward() is called, request.attributes.get('_route') is null.

This is because the duplicate is called with a non empty array for attributes (_controller) so the attributes are not totally cloned from the previous request.
And should the _route value take the old route? or the new one?

Christophe Coevoet
stof commented May 09, 2011

Forwarding does not forward to a route but to a controller. You don't even need to have a route for your controller.

Fabien Potencier
fabpot commented May 09, 2011

You should never rely on the _route. It's only available for debugging purpose.

Fabien Potencier fabpot closed this May 09, 2011
Vincent Lechemin
Maël Nison

@fabpot What is the right way to access to the current route name ? My use case is to make a generic listener in KernelEvents::REQUEST.

Christophe Coevoet

$request->attribute->get('_route') is the way to access it. But if you use forward, there is simply no route as you are generally forwarding to a controller, not to a path needing the router to find the controller.

Maël Nison

I understand, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.