假设这个表单使用了一个虚构的Animal
文档对象类,它在symfony2ZooCollection
中只有两个属性(“名称”和“颜色”)。
我正在寻找一个可行的简单愚蠢的解决方案,用给定的对象自动预填充表单字段(例如更新?)。
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);
...
}