-->

使用sonata_type_collection根据自定义形式类型,而不是与另一实体的属性/关系(u

2019-07-29 18:57发布

是否有可能使用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 
));

Answer 1:

相反,在你的例子一个自定义类型,你也可以使用原生的实体类型。

$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
                                )
                            )
                        )


文章来源: using sonata_type_collection against a custom form type instead of a property/relationship with another entity