如何通过传递2个或更多参数来重定向到另一个操作?
这段代码:
$this->redirect('input/new?year=' . $year . '&month=' . $month);
URL中的结果:
http://.../input?year=2009&month=9
那是正常的,“redirect”重定向到一个绝对 URL。你可以这样做:
$this->redirect($this->generateUrl('default', array('module' => 'input',
'action' => 'new', 'year' => $year, 'month' => $month)));
在当前支持的Symfony版本(2.7+)中,重定向甚至更加容易了(而且,你还可以选择在末尾添加状态码):
return $this->redirectToRoute(
'default',
array('year' => $year, 'month' => $month),
Response::HTTP_MOVED_PERMANENTLY // = 301
);
$this->redirect('route_name', array('year' => $year, 'month' => $month));
我认为这不是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);
$this->redirectToRoute('routename', ['param1' => 'value', ['param2' => 'value'])
。 - Quentin S.