3

I've been following this tutorial to create a registration form with 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.

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. 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. 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). Only a Apache restart helped then.

This is my createAction inside the Account controller

// '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., so apparently it crashes when calling the handleRequest($request) method.

What is it, that's so horribly wrong?

Tell me if you need the code of any other scripts!

padarom
  • 3,529
  • 5
  • 33
  • 57
  • Did you add getUsername() and setUsername() in the entity class ? – timmz Jun 27 '14 at 10:49
  • @Timmz: I did. The User class has getters and setters for every value that's being addressed in the form. – padarom Jun 27 '14 at 11:00
  • try: \Doctrine\Common\Util\Debug::dump($request); to see what is in this object .. – timmz Jun 27 '14 at 16:31
  • Did you eventually found solution? I'have similar issue: script stops at handleRequest($request) - without any error or exception. App logs are empty, php logs are empty, nginx logs are empty. Locally (xampp on windows, php 5.5.10) works like a charm. But crashes on server (ubuntu, nginx, php-fpm 5.5.13). – Marek Aug 13 '14 at 08:09

1 Answers1

2

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 {
        $form->handleRequest($request);
    } catch (\Exception $e) {
        echo "failed : ".$e->getMessage();
    }

what exception is throwed ?

john Smith
  • 17,409
  • 11
  • 76
  • 117
  • For some reason it doesn't throw an exception if I use the try-catch-block. But shouldn't Symfony catch exceptions on its own and trace them for me in the `dev`-environment? – padarom Jun 27 '14 at 11:37
  • I have also tried to bind a custom error handler via `set_error_handler()` in case it's an error instead of an exception. The script still just stops executing instead of catching anything. – padarom Jun 27 '14 at 11:48
  • yes, this is weird, do you "use " RegistrationType and Registration classes in you Document ? try to set them as variables before like $type = new RegistrationType() .. maybe this is the point of failure – john Smith Jun 27 '14 at 12:17
  • I do. Both `Test\TestBundle\Form\Type\RegistrationType` and `Test\TestBundle\Form\Model\Registration` are being `use`d. – padarom Jun 27 '14 at 12:48