Symfony2 Form pre-fill fields with data

Viewed 12377

Assume for a moment that this form utilizes an imaginary Animal document object class from a ZooCollection that has only two properties ("name" and "color") in .

I'm looking for a working simple stupid solution, to pre-fill the form fields with the given object auto-magically (eg. for updates ?).

Acme/DemoBundle/Controller/CustomController:

public function updateAnimalAction(Request $request)
{
    ...
    // Create the form and handle the request
    $form = $this->createForm(AnimalType(), $animal);

    // Set the data again          << doesn't work ?
    $form->setData($form->getData());
    $form->handleRequest($request);
    ...
}
2 Answers
Related