[英]How to redirect other URL in Symfony3 with parameter
I have trouble how to redirect other URL with parameter. 我在如何使用参数重定向其他URL时遇到麻烦。 In the following code, it shows the error message when $resultFlg is equal to True.
在下面的代码中,当$ resultFlg等于True时,它将显示错误消息。
The message states that 'Unable to generate a URL for the named route "snsForm" as such route does not exist'. 该消息指出“无法为命名路由“ snsForm”生成URL,因为这样的路由不存在”。 I don't understand the reason and the solution.
我不明白原因和解决方案。 Please use routing.yml as a reference.
请使用routing.yml作为参考。 Then, Symfony version is 3.0.4-DEV.
然后,Symfony版本是3.0.4-DEV。
src/AppBundle/Controller/UserController.php src / AppBundle / Controller / UserController.php
/**
* @Route("/form", name="userForm")
*/
public function newAction(Request $request)
{
........
$resultFlg = $this->existedUserCheck($userId, $password);
if($resultFlg){
// failed
return $this->redirect($this->generateUrl('snsForm'));
}else{
$loginResultMessage = 'No registered User Id: ' . $userId;
}
.......
}
/**
* @Route("/snsForm", name="regsiterSnsRoute")
*/
public function registerSnsInfoAction(Request $request)
{
.......
}
app/config/routing.yml app / config / routing.yml
app:
resource: "@AppBundle/Controller/"
type: annotation
You need to direct to the name of the route not the url. 您需要直接输入路由名称而不是网址。 In your case it is 'regsiterSnsRoute'
您的情况是“ regsiterSnsRoute”
return $this->redirect($this->generateUrl('regsiterSnsRoute'));
also you can shorten that line to 你也可以把那条线缩短到
return $this->redirectToRoute('regsiterSnsRoute');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.