Symfony 在实体表单类型中格式化选项列表选项
我使用基于选项的实体表单类型,以便在Sonata管理表单中提供选项列表。我希望使用一个子属性来显示选项列表中的元素集合 有人知道如何提供要显示在chocie列表中的标签,或者如何为choice列表数组提供格式吗Symfony 在实体表单类型中格式化选项列表选项,symfony,symfony-forms,symfony-sonata,Symfony,Symfony Forms,Symfony Sonata,我使用基于选项的实体表单类型,以便在Sonata管理表单中提供选项列表。我希望使用一个子属性来显示选项列表中的元素集合 有人知道如何提供要显示在chocie列表中的标签,或者如何为choice列表数组提供格式吗 $formMapper->add( 'frArea', 'entity', array( 'class' => 'myVendor\myBundleBundle\View\myEntity', //When us
$formMapper->add( 'frArea', 'entity', array(
'class' => 'myVendor\myBundleBundle\View\myEntity',
//When using a child property here, choice list gets corrupted/bad formatted
//'property' => 'child.property',
'property' => 'property',
'em' => 'formacions',
'query_builder' => function( EntityRepository $er )
{
return $er->createQueryBuilder( 'qb' )
->add( 'select', 'm' )
->add( 'from', 'myVendor\myBundleBundle\View\myEntity m' );
//->leftJoin('a.idiomes', 'ai');
},
'required' => false,
'label' => ucfirst( $this->trans( 'my_label', array(), $this->translationDomain, $this->langCode ) )
) );
以以下方式使用property选项时,“property”=>“child.property”
会出现以下错误:
Neither property "nom" nor method "getProperty()" nor method "isProperty()" exists in class "Doctrine\ORM\PersistentCollection"
这是参数
属性的角色
!无需向Symfony指明哪个字段是选项的值,它采用ID列,因此属性用于显示;) Thx,但正如您在文章中看到的,当属性值是子实体property时,我遇到了一些问题。我编辑了这篇文章以显示我在执行此操作时遇到的错误。您是否尝试将公共访问器从MyEntity m写入相关子实体?否,将尝试在此处发布。谢谢!不是我想要的解决方案,但至少得到了我想要的。谢谢!