php 带有 2 个参数的 symfony 重定向

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1496975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:49:32  来源:igfitidea点击:

symfony redirect with 2 parameters

phpredirectsymfony1

提问by kipelovets

how can i redirect to another action passing 2 or more parameters? this code:

我如何重定向到另一个传递 2 个或更多参数的动作?这段代码:

$this->redirect('input/new?year=' . $year . '&month=' . $month);

results in URL:

结果在网址:

http://.../input?year=2009&month=9

http://.../input?year=2009&month=9

回答by xarch

Well, that's normal, "redirect" redirect to an absolute URL. You can do that:

嗯,这是正常的,“重定向”重定向到绝对 URL。你可以这样做:

$this->redirect($this->generateUrl('default', array('module' => 'input',
'action' => 'new', 'year' => $year, 'month' => $month)));

回答by forsberg

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
);

回答by Guillermo Gutiérrez

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 上测试)

回答by jochil

I think this is no normal symfony behavior. Have you defined some routing rules?

我认为这不是正常的 symfony 行为。您是否定义了一些路由规则?

Have you also tried this:

你是否也试过这个:

$this->redirect('module/action?'.http_build_query($paramsArray));

回答by Andrei Dziahel

Strange thing. Does

奇怪的事情。做

$this->redirect('@default?module=input&action=new&year=' . $year . '&month=' . $month);

work for you?

为你工作?

回答by Mohammad

$this->redirect('input/new/year/' . $year . '/month/' . $month);