kip*_*ets 31 php redirect symfony1
如何重定向到另一个传递2个或更多参数的动作?这段代码:
$this->redirect('input/new?year=' . $year . '&month=' . $month);
Run Code Online (Sandbox Code Playgroud)
结果在URL中:
http://.../input?year=2009&month=9
xar*_*rch 55
嗯,这是正常的,"重定向"重定向到绝对URL.你可以这样做:
$this->redirect($this->generateUrl('default', array('module' => 'input',
'action' => 'new', 'year' => $year, 'month' => $month)));
Run Code Online (Sandbox Code Playgroud)
在目前支持的Symfony版本(2.7+)中,它更容易:
return $this->redirectToRoute('default', array('year' => $year, 'month' => $month));
Run Code Online (Sandbox Code Playgroud)
您还可以使用重定向,指定路由名称和参数数组:
$this->redirect('route_name', array('year' => $year, 'month' => $month));
Run Code Online (Sandbox Code Playgroud)
(在 Symfony 1.4 上测试)
| 归档时间: |
|
| 查看次数: |
82882 次 |
| 最近记录: |