【发布时间】:2014-01-17 17:36:03
【问题描述】:
我正在寻找一种方法来填充我的表单集合。我正在通过原型制作自己的收藏。
在我的控制器中:
//samplecode... a person can have many cats
$em = $this->getDoctrine()->getManager();
$person= $em->getRepository('UserBundle:Person')->find(0);
$form = $this->createForm(new PersonType(), $person);
我有一个表单集合,我想用我的主要实体(人)中已经存在的所有数据(猫)填充这些表单。我的最后一种方法被注释掉了。
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('cats', 'collection', array(
'type' => new CatType(),
'allow_add' => true,
'allow_delete' => true,
'mapped'=> false,
'data_class' => 'Yoda\UserBundle\Entity\Cat',
// 'data' => $options["data"]->getCats(),
))
->getForm()
;
}
还有猫的FormType:
->add('name', 'text', array(
'read_only' => true,
'disabled' => true,
))
->add('price', 'money', array(
'label' => 'Price',
))
提前致谢。
【问题讨论】:
标签: symfony collections prototype populate