我一直在关注 this tutorial使用 Symfony 2.5 创建注册表单。
我所做的唯一不同是在我的 User
类中为用户名增加了一个字段,并将其呈现为 UserType
表单。
当将表单提交到 account_create
路由(最终使用帐户 Controller 中的 create
操作)时,它不会正确处理表单。该页面显示为空白,甚至不再显示分析器。
此外,脚本似乎破坏了我的 Apache(我通过 XAMPP 在 Windows 上本地运行它),因为我在提交表单后尝试做的所有事情都会导致无限加载。这意味着无论我接下来尝试访问我服务器上的哪个页面(即使它只是分析器),我都不能。它只是一直在加载(我曾经等过 10 分钟以上)。那时只有 Apache 重启有帮助。
这是我在帐户 Controller 中的 createAction
// 'account_create' route
// TestBundle:Account:create
public function createAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
echo "Doctrine managed. ";
$form = $this->createForm(new RegistrationType(), new Registration());
echo "Form created. ";
$form->handleRequest($request);
echo "Request handled. ";
if ($form->isValid()) {
$registration = $form->getData();
echo "Form data received. ";
$em->persist($registration->getUser());
echo "User persisted. ";
$em->flush();
echo "Toilet flushed. ";
return $this->redirect($this->generateUrl('admin_page'));
}
return $this->render(
'TestBundle:Account:register.html.twig',
array('form' => $form->createView())
);
}
它只输出Doctrine managed。表单已创建。
,显然它在调用 handleRequest($request)
方法时崩溃了。
这是怎么回事,错得离谱吗?
如果您需要任何其他脚本的代码,请告诉我!
最佳答案
我知道这不是的答案,但无论如何它不适合作为评论和调试这个的重要步骤
将处理请求放在 try block 中并回显异常
try {
$form->handleRequest($request);
} catch (\Exception $e) {
echo "failed : ".$e->getMessage();
}
抛出什么异常?
关于php - Symfony 表单提交不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24449112/