using sonata_type_collection against a custom form type instead of a property/relationship with another entity

杀马特。学长 韩版系。学妹 提交于 2019-12-05 05:31:27

问题


is it possible to use sonata_type_collection against a custom form type instead of a property/relationship with another entity?

Something like this:

$formMapper->add('foo', 'sonata_type_collection',
    array('type' => new \myVendor\myBundleBundle\Form\Type\BlockType() 
));

Which throws me the following error

The current field `contingut` is not linked to an admin. Please create one for the target entity : ``

EDIT:

Something like this did the trick:

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

回答1:


Instead of a custom type in your example, you can also use a native entity type.

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


来源:https://stackoverflow.com/questions/10932028/using-sonata-type-collection-against-a-custom-form-type-instead-of-a-property-re

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!