【发布时间】:2013-12-10 16:40:24
【问题描述】:
暂时假设此表单使用来自ZooCollection 的虚构Animal 文档对象类,该对象类在symfony2 中只有两个属性(“名称”和“颜色”)。
我正在寻找一个工作简单愚蠢的解决方案,用给定的对象预填充 表单字段 auto -神奇地(例如更新?)。
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);
...
}
【问题讨论】:
-
只设置动物对象的属性怎么样?
标签: symfony2 php forms symfony controller doctrine-mongodb