我正在使用ManyToMany这样在Symfony中构建表单:
常见问题实体
/**
* @ORM\ManyToMany(
* targetEntity="XXX\AppBundle\Entity\LegalAndHelp\FaqGroups",
* inversedBy="faq"
* )
* @ORM\JoinTable(
* name="faq_groups_faq",
* joinColumns={@ORM\JoinColumn(name="faq_id", referencedColumnName="id", onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="faq_group_id", referencedColumnName="id", onDelete="CASCADE")}
* )
*/
protected $faqGroups;
FaqGroups实体
/**
* @ORM\ManyToMany(
* targetEntity="XXX\AppBundle\Entity\LegalAndHelp\Faq",
* mappedBy="faqGroups",
* cascade={"persist"}
* )
*/
protected $faq;
然后我要构建如下形式的表格:
$builder
->add('faqGroups', EntityType::class, [
'class' => FaqGroups::class,
'choice_label' => function ($faqGroups) {
return $faqGroups->getDisplayTitle($this->userLanguage);
},
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('fg');
},
'placeholder' => 'admin.faq.choose.group',
'constraints' => [
new Count([
'min' => 1,
'minMessage' => 'blabla'
])
]
])
现在(在编辑部分中),我已填充了呈表格形式的对象,并且应该能够看到包括已选择设置值的<select>
在内的所有数据。问题在于,当存在选择时,它不会显示设置值。当我更改此设置并添加'multiple' => true, 'expanded' => false,
时,选择就可以了。但我希望将其视为选择下拉列表,而不是多选或复选框选项。