如何在 Symfony 4.1 中设置选项名称?
How to set the choice option name in Symfony 4.1?
看了很多遍Symfony choices,我还是不明白如何在我的下拉列表中设置选项的名称?
class CategoryType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('parentCategory', EntityType::class, array(
'class' => Category::class,
'query_builder' => function (EntityRepository $er) {
$er->createQueryBuilder('c')
->orderBy('c.name', 'ASC');
},
'choice_label' => 'parent category',
))
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Category::class,
]);
}
}
把'choice_label' => 'parent category'
改成'choice_label' => 'name'
解决了问题,然后输出
看了很多遍Symfony choices,我还是不明白如何在我的下拉列表中设置选项的名称?
class CategoryType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name')
->add('parentCategory', EntityType::class, array(
'class' => Category::class,
'query_builder' => function (EntityRepository $er) {
$er->createQueryBuilder('c')
->orderBy('c.name', 'ASC');
},
'choice_label' => 'parent category',
))
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Category::class,
]);
}
}
把'choice_label' => 'parent category'
改成'choice_label' => 'name'
解决了问题,然后输出