Reputation: 81
Im having trouble trying to get POST values from a simple HTML form in symfony 2. This is what my controller method does:
/**
* @Route("/process-login/", name="process login")
* @Method("POST")
*/
public function processLoginAction()
{
$name = $this->request->request->get('username');
$password = $this->request->request->get('password');
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery('SELECT u.id FROM AppBundle:Admin u WHERE u.name = :name AND u.password = :password')
->setParameter('name', $name)
->setParameter('password', $password);
$result = $query->getOneOrNullResult();
if($result < 1)
{
$this->session->getFlashBag()->add('error', 'Incorrect login details');
$action = $this->redirectToRoute('login');
}
else
{
$this->session->start();
$this->session->set('admin', $name);
$action = $this->redirectToRoute('homepage');
}
return $action;
}
Whenever I process the form I get the error No route found for "POST /process-login".
Where could be the issue? P.S. works with GET
Upvotes: 0
Views: 56
Reputation: 4972
Its probably because of the slash in the end. delete the / from the end of the route.
/**
* @Route("/process-login", name="process login")
* @Method("POST")
*/
it should be the case.
also run
php app/console router:debug
to see if the route is even identified by Symfony2.
Upvotes: 1