【发布时间】:2012-06-11 12:29:11
【问题描述】:
是否可以将sonata_type_collection 用于自定义表单类型而不是与另一个实体的属性/关系?
类似这样的:
$formMapper->add('foo', 'sonata_type_collection',
array('type' => new \myVendor\myBundleBundle\Form\Type\BlockType()
));
这会引发以下错误
The current field `contingut` is not linked to an admin. Please create one for the target entity : ``
编辑:
这样的事情可以解决问题:
$formMapper->add('contingut', 'collection', array(
'type' => new \myVendor\myBundleBundle\Form\Type\Block1Type(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false
));
【问题讨论】:
-
从来没有人将基于模型的表单与奏鸣曲结合使用?我的意思是,每个人都曾经使用过 SOnata,仅用于基于实体的表单吗?提前致谢!
-
到目前为止,我没有使用自定义表单类型,而是覆盖了 form_admin_fields.html 模板,然后捕获集合名称,例如foo 并包含一个 _foo.html.twig 模板,该模板基于 edit_orm_one_to_many.html.twig,例如在使用 OneToMany 时。然后我在 twig 中根据需要定义表单和模板。但是使用自定义类型听起来很有趣! @user846226 对你有用吗?
标签: symfony symfony-forms symfony-sonata sonata-admin