假設此表單利用Animal
文檔對象類別ZooCollection
,該文檔對象類別在symfony2中只有兩個屬性(「名稱」和「顏色」)。Symfony2使用數據形成預填充字段
我在尋找一個工作簡單愚蠢的方案,以預填的表單字段與給定對象自動神奇(如更新?)。
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);
...
}
大約只需設置動物對象的屬性是什麼? –