symfony redirect with 2 parameters

社会主义新天地 提交于 2019-12-17 17:48:18

问题


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

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

results in URL:

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


回答1:


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

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



回答2:


In currently supported Symfony versions (2.7+) it's even easier:

return $this->redirectToRoute('default', array('year' => $year, 'month' => $month));



回答3:


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)




回答4:


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

Have you also tried this:

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



回答5:


Strange thing. Does

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

work for you?




回答6:


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


来源:https://stackoverflow.com/questions/1496975/symfony-redirect-with-2-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!