我尝试使用EventListener但是我有错误: 必须管理传递到选择字段的实体。也许坚持他们在实体经理?
ExampleType.php
$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event) {
$form = $event->getForm();
// this would be your entity, i.e. SportMeetup
$data = $event->getData();
$category = $data->getCategory();
$tagi = null === $category ? array() : $category->getTags();
$form->add('tags', 'entity', array(
'class' => 'MyAppBundle:Tag',
'placeholder' => '',
'choices' => $tagi,
));
}
);
// Category.php(entity)
/**
* Get tags
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getTags()
{
return $this->tags;
}