简体   繁体   English

Symfony表格提交不起作用

[英]Symfony form submission doesn't work

I've been following this tutorial to create a registration form with Symfony 2.5. 我一直在遵循本教程来使用Symfony 2.5创建注册表单。

The only difference I made, was an additional field for the username in my User class and rendering it in the UserType form. 我唯一的区别是在User类中为用户名添加了一个字段,并以UserType形式呈现它。

When submitting the form to the account_create -route (which ultimately uses the create action in the Account controller) it won't properly handle the form. 将表单提交到account_create -route(最终在Account控制器中使用create动作)时,它将无法正确处理该表单。 The page shows up blank, not even the profiler shows up anymore. 该页面显示为空白,甚至不再显示探查器。

Additionally it seems like the script breaks my Apache (I'm running this locally on Windows via XAMPP ), as everything I try to do after submitting the form once results in endless loading. 此外,该脚本似乎破坏了我的Apache(我正在Windows上通过XAMPP在本地运行此脚本),因为一旦提交表单后,我尝试执行的所有操作都会导致无休止的加载。 This means that no matter which page on my server I try to access next (even if it's just the profiler), I can't. 这意味着无论我尝试访问服务器上的哪个页面(即使只是探查器),我都无法访问。 It just keeps loading forever (I've been waiting over 10 minutes once). 它只会永远保持加载状态(我已经等待了10分钟以上)。 Only a Apache restart helped then. 那时只有Apache重新启动才有帮助。

This is my createAction inside the Account controller 这是我在Account控制器中的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())
    );
}

It only outputs Doctrine managed. Form created. 它仅输出受Doctrine managed. Form created. Doctrine managed. Form created. , so apparently it crashes when calling the handleRequest($request) method. ,因此显然在调用handleRequest($request)方法时会崩溃。

What is it, that's so horribly wrong? 这是什么,那太可怕了吗?

Tell me if you need the code of any other scripts! 告诉我您是否需要其他脚本的代码!

i know this is not the answer, but anyway its not fitting as comment and an important step to debug this 我知道这是不是问题答案,但无论如何它不是配件,评论和调试这重要的一步

put handle request in a try block and echo the exception 将句柄请求放入try块并回显异常

    try {
        $form->handleRequest($request);
    } catch (\Exception $e) {
        echo "failed : ".$e->getMessage();
    }

what exception is throwed ? 抛出什么异常?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM