[英]Optional get parameter (with slashes) in default / route
The main page on my website is an empty link, like: 我网站上的主页是一个空白链接,例如:
www.randomlink.com/
That's the controller with the "/"
route. 这就是带有
"/"
路由的控制器。 The problem is that I have to use get parameters here, according to the following pattern: 问题是我必须根据以下模式在这里使用get参数:
key1/value1/key2/value2
I add these parameters on form submit, and the form redirects back to the main page. 我在表单提交上添加了这些参数,并且表单重定向回到了主页。
The problem is that, as you can see, I get: 如您所见,问题是,我得到:
www.randomlink.com/key1/value1/key2/value2
And thus it opens key1 controller, instead of the default one. 因此,它将打开key1控制器,而不是默认的控制器。
/**
* Display dashboard
*
* @Route("/{path}",
* name="dashboard",
* defaults={"path" = "-1"},
* requirements={"path" = ".+"})
* @Template()
*/
public function displayAction($path, Request $request)
{
if($_POST)
{
// add get parameters to $path
return $this->redirect($this->generateUrl('dashboard', ['path' => $path]));
}
// do something
}
How can I solve this issue? 我该如何解决这个问题?
Probably your routing configuration order is not correct: see "Earlier Routes always Win" in the docs 可能是您的路由配置顺序不正确:请参阅文档中的“更早的路由总会获胜”
Workaround: What about using query string like: www.randomlink.com/?path=key1/value1/key2/value2
, then $request->query->get('path')
? 解决方法:如何使用查询字符串,例如:
www.randomlink.com/?path=key1/value1/key2/value2
? $request->query->get('path')
/ www.randomlink.com/?path=key1/value1/key2/value2
,然后使用$request->query->get('path')
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.