【发布时间】:2016-03-11 15:50:39
【问题描述】:
这是我在控制器中的代码:
$entity_options = array(
'class' => 'ACCUEILBundle:Param',
'property' => 'description',
'query_builder' => function(\Doctrine\ORM\EntityRepository $er) {
return $er->createQueryBuilder('p')
->where("p.categorie = 5")
->orderBy('p.description', 'ASC');
}
);
if($entity_type !== null) {
$entity_options['data'] = $this->getDoctrine()->getManager()->find('ACCUEILBundle:Param', $entity_type);
}
$formBuilder->add('entity_types', 'entity', $entity_options);
$form->$formBuilder->getForm();
如果我在列表中选择一个项目并提交表单,则 $form->getData()['entity_types'] 返回所选的 Param 对象。
如果我想用'data'选项强制默认选中的项目并显示$form->getData(),它会返回一个空数组。
我应该从哪里获得我刚刚使用“数据”选项声明的默认选定项。
【问题讨论】: