我很难用参数重定向其他URL。在下面的代码中,当$resultFlg等于True时,它会显示错误消息。
消息指出"无法为命名路由"snsForm"生成URL,因为此类路由不存在"。我不明白原因和解决办法。请使用routing.yml作为参考。然后,Symfony版本是3.0.4-DEV.
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:
resource: "@AppBundle/Controller/"
type: annotation
您需要指向路由的名称,而不是url。在您的情况下,它是"regsiterSnsRoute"
return $this->redirect($this->generateUrl('regsiterSnsRoute'));
你也可以把这条线缩短为
return $this->redirectToRoute('regsiterSnsRoute');