我正在尝试将实体置于自己的表单中。我懒得记住一个getData()方法,但它在表单中不存在,我不记得如何使用它。
有没有办法让buildform方法中的实体不使用事件监听器?
我的意思是,像这样:
public function buildForm(FormBuilderInterface $builder, array $options)
{
/*some method to get the entity of the form such as getEntity????????*/
$builder->add('field');
}
答案 0 :(得分:66)
我找到了它:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$entity = $builder->getData();
$builder->add('field');
}