我想创建自己的自定义表单类型的sonata_type_collection,但是我在执行它时遇到了麻烦。
起初我创建了自己的类型类并将其注册为服务:
class SonataTypeCollectionWithSearchType extends AbstractType {
public function setDefaultOptions(OptionsResolverInterface $resolver) {
}
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add($options['type_options']['stcwst_attribute'], 'sonata_type_collection',array('data_class' => $options['type_options']['stcwst_class']));
}
public function getName()
{
return 'sonata_type_collection_with_search';
}
public function getParent()
{
return 'sonata_type_collection';
}
}
service.yml:
services:
sonata_type_collection_with_search:
class: ASV\CoreBundle\Form\Type\SonataTypeCollectionWithSearchType
tags:
- { name: form.type, alias: sonata_type_collection_with_search }
在UniversityAdmin课程中,我将其添加到formMapper:
->add('studycourses', 'sonata_type_collection_with_search', array(
'type_options' => array('delete' => false,
'stcwst_attribute' => 'studycourse',
'stcwst_class' => 'ASV\UniversityBundle\Entity\University'
), array(
'edit' => 'inline',
'inline' => 'table',
'sortable' => 'position',
))
但现在我收到了这个错误:
FatalErrorException:错误:在a上调用成员函数getAdmin() 非对象 供应商/奏鸣曲项目/学说,phpcr管理员束/索纳塔/ DoctrinePHPCRAdminBundle /表格/分机/ CollectionTypeExtension.php 第32行
任何想法出了什么问题?甚至可以将sonata_type_collection作为父级吗?