Symfony 表单 - 无法收集 POST 个值
Symfony form - not able to collect POST values
我在尝试从 symfony 2 中的简单 HTML 表单获取 POST 值时遇到问题。这就是我的控制器方法所做的事情:
/**
* @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;
}
每当我处理表格时,我都会收到错误消息
找不到 "POST /process-login".
的路线
问题出在哪里?
P.S。使用 GET
可能是因为最后的斜线。
从路线末尾删除 / 。
/**
* @Route("/process-login", name="process login")
* @Method("POST")
*/
应该是这样的。
还有运行
php app/console router:debug
查看路由是否被 Symfony2 识别。
我在尝试从 symfony 2 中的简单 HTML 表单获取 POST 值时遇到问题。这就是我的控制器方法所做的事情:
/**
* @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;
}
每当我处理表格时,我都会收到错误消息 找不到 "POST /process-login".
的路线问题出在哪里? P.S。使用 GET
可能是因为最后的斜线。 从路线末尾删除 / 。
/**
* @Route("/process-login", name="process login")
* @Method("POST")
*/
应该是这样的。
还有运行
php app/console router:debug
查看路由是否被 Symfony2 识别。