我正在使用Symfony 2.6.1。
实体配置:http://pastebin.com/rMkYHjkE
管理员班:
class PlaceAdmin extends Admin
{
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
//other fields
->add('types', 'collection', array(
'type' => new PlaceType,
'allow_add' => true,
));
;
}
//other stuff
}
当我尝试编辑选定的实体时:
指定类型为“字符串,Symfony \ Component \ Form \ ResolvedFormTypeInterface或Symfony \ Component \ Form \ FormTypeInterface”,“ Syloc \ Bundle \ GooglePlacesBundle \ Entity \ PlaceType”的预期参数
从文档:
这是此集合中每个项目的字段类型(例如,文本,选项等)。例如,如果您有一组电子邮件地址,则可以使用电子邮件类型。如果要嵌入其他表单的集合,请创建表单类型的新实例,并将其作为此选项传递。
因此,您需要执行以下操作:
class PlaceAdmin extends Admin
{
// Fields to be shown on create/edit forms
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
//other fields
->add('types', 'collection', array(
'type' => 'text',
'allow_add' => true,
));
;
}
//other stuff
}
您没有为collection
表单类型定义实体类型。也许您也在寻找要做的事情sonata_type_collection
,而不仅仅是collection
?您也不需要通过此Form Type传递子Entity类型,因为它是从Entity属性自动解析的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句