I have trouble how to redirect other URL with parameter. In the following code, it shows the error message when $resultFlg is equal to True.
The message states that 'Unable to generate a URL for the named route "snsForm" as such route does not exist'. I don't understand the reason and the solution. Please use routing.yml as a reference. Then, Symfony version is 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
You need to direct to the name of the route not the url. In your case it is 'regsiterSnsRoute'
return $this->redirect($this->generateUrl('regsiterSnsRoute'));
also you can shorten that line to
return $this->redirectToRoute('regsiterSnsRoute');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.