【发布时间】:2010-12-02 14:09:40
【问题描述】:
如何重定向到另一个传递 2 个或更多参数的操作?
这段代码:
$this->redirect('input/new?year=' . $year . '&month=' . $month);
网址中的结果:
http://.../input?year=2009&month=9
【问题讨论】:
如何重定向到另一个传递 2 个或更多参数的操作?
这段代码:
$this->redirect('input/new?year=' . $year . '&month=' . $month);
网址中的结果:
http://.../input?year=2009&month=9
【问题讨论】:
嗯,这很正常,“重定向”重定向到绝对 URL。你可以这样做:
$this->redirect($this->generateUrl('default', array('module' => 'input',
'action' => 'new', 'year' => $year, 'month' => $month)));
【讨论】:
$this->redirectToRoute('routename', ['param1' => 'value', ['param2' => 'value'])
在当前支持的 Symfony 版本(2.7+)it's even easier(另外,您还可以选择在末尾添加状态码):
return $this->redirectToRoute(
'default',
array('year' => $year, 'month' => $month),
Response::HTTP_MOVED_PERMANENTLY // = 301
);
【讨论】:
也可以使用redirect,指定路由名称和参数数组:
$this->redirect('route_name', array('year' => $year, 'month' => $month));
(在 Symfony 1.4 上测试)
【讨论】:
我认为这不是正常的 symfony 行为。你定义了一些路由规则吗?
你也试过这个吗:
$this->redirect('module/action?'.http_build_query($paramsArray));
【讨论】:
奇怪的东西。有没有
$this->redirect('@default?module=input&action=new&year=' . $year . '&month=' . $month);
为你工作?
【讨论】:
$this->redirect('input/new/year/' . $year . '/month/' . $month);
【讨论】: