[英]symfony redirect with 2 parameters
how can i redirect to another action passing 2 or more parameters?我如何重定向到另一个传递 2 个或更多参数的动作? this code:
这段代码:
$this->redirect('input/new?year=' . $year . '&month=' . $month);
results in URL:结果在网址:
http://.../input?year=2009&month=9
Well, that's normal, "redirect" redirect to an absolute URL.嗯,这是正常的,“重定向”重定向到绝对 URL。 You can do that:
你可以这样做:
$this->redirect($this->generateUrl('default', array('module' => 'input',
'action' => 'new', 'year' => $year, 'month' => $month)));
In the currently supported Symfony versions (2.7+) it's even easier (plus, you can optionally add also the status code at the end):在当前支持的 Symfony 版本(2.7+)中,它更容易(此外,您还可以选择在末尾添加状态代码):
return $this->redirectToRoute(
'default',
array('year' => $year, 'month' => $month),
Response::HTTP_MOVED_PERMANENTLY // = 301
);
You can also use redirect, specifying the route name and the parameter array:您还可以使用重定向,指定路由名称和参数数组:
$this->redirect('route_name', array('year' => $year, 'month' => $month));
(Tested on Symfony 1.4) (在 Symfony 1.4 上测试)
I think this is no normal symfony behavior.我认为这不是正常的 symfony 行为。 Have you defined some routing rules?
您是否定义了一些路由规则?
Have you also tried this:你是否也试过这个:
$this->redirect('module/action?'.http_build_query($paramsArray));
Strange thing.奇怪的事情。 Does
做
$this->redirect('@default?module=input&action=new&year=' . $year . '&month=' . $month);
work for you?为你工作?
$this->redirect('input/new/year/' . $year . '/month/' . $month);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.