设置三条路径
为控制器设置三个动作
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');
}
加载以下网址时:
获得的结果是:
在检查路由是否通过转发持续存在之后,我的意外是意识到转发后#"路径会从Request属性ParameterBag中丢失。
是否有其他方法可以使用参数检索请求匹配的路由?
为什么路由不会通过转发持续存在?
谢谢大家
答案 0 :(得分:1)
这是我正在寻找的答案。
答案 1 :(得分:0)
forward
方法取three parameters,第三个是查询参数,所以尝试修改转发,如:
public function secondAction($argument){
return $this->forward('Bundle:Controller:first',array(),array('argument'=>$argument));
}
希望这个帮助