针对自定义表单类型使用 sonata_type_collection 而不是与另一个实体的属性/关系

2024-04-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 : ``

EDIT:

像这样的事情就成功了:

$formMapper->add('contingut', 'collection', array(                                 
    'type' => new \myVendor\myBundleBundle\Form\Type\Block1Type(),
    'allow_add' => true,
    'allow_delete' => true,
    'by_reference' => false 
));

您还可以使用本机实体类型,而不是示例中的自定义类型。

$formMapper->add('cars',
                            'collection',
                            array(
                                'type' => 'entity',
                                'allow_add' => true,
                                'allow_delete' => true,
                                'by_reference' => false,
                                'label' => false,
                                'options' => array(
                                    'class' => 'YourBundle:Car',
                                    'property' => 'name',
                                    'label' => false
                                )
                            )
                        )
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

针对自定义表单类型使用 sonata_type_collection 而不是与另一个实体的属性/关系 的相关文章

随机推荐