Supose three paths
- /first/action/{argument} #where argument can be empty
- /second/action/{argument} #where argument is required
- /third/action/{argument} #where argument is required too
Supose a Controller with three actions
public function firstAction(Request $request, $argument=null){
$route_params = (array) $request->attributes->get('_route_params');
$argument=(empty($argument) ? $route_params['argument'] : $argument;
return new Response('This was the argument'.(string)$argument);
}
public function secondAction($argument){
return $this->forward('Bundle:Controller:first',array('argument'=>$argument));
}
public function thirdAction($argument){
return $this->forward('Bundle:Controller:first');
}
When loading following urls:
- http:// localhost/first/action/passed
- http:// localhost/second/action/forwarded
- http:// localhost/third/action/forwarded_too
obtained results were:
- 'This was the argument passed'
- 'This was the argument forwarded'
- 'This was the argument'
After checking if route persisted through forwarding, my surprise was to realize that "route get lost from Request attributes ParameterBag after forwarding".
Is there any other way to retrieve the request matched route with arguments?
Why route doesn't persist through forwarding?
Thanks everyone