Symfony - ChoiceType返回

时间:2018-05-10 08:34:04

标签: php symfony select drop-down-menu

我提出了表单请求,但无法为Actions字段的select选项定义ChoiceType。

$form = $this->createFormBuilder()
        ->add('title', TextType::class, array('label' => 'Label1', 'attr' => ['class'=>'form-control']))
        ->add('actions', ChoiceType::class, array('a' => 'Option 1', 'b' => 'Option 2','c' => 'Option 3'))
        ->add('save', SubmitType::class, array('label' => 'Send', 'attr' => [
            'class' => 'btn btn-primary action-save'
        ]))
        ->getForm();

任何想法?

1 个答案:

答案 0 :(得分:2)

https://symfony.com/doc/current/reference/forms/types/choice.html#choices

 $form = $this->createFormBuilder()
        ->add('title', TextType::class, array('label' => 'Label1', 'attr' => ['class'=>'form-control']))
        ->add('actions', ChoiceType::class, array(
            'choices' => array('a' => 'Option 1', 'b' => 'Option 2','c' => 'Option 3')

        ))
        ->add('save', SubmitType::class, array('label' => 'Send', 'attr' => [
            'class' => 'btn btn-primary action-save'
        ]))
        ->getForm();
相关问题