用formbuilder制作整数值的单选按钮

时间:2015-04-16 05:17:21

标签: html symfony formbuilder

我正在尝试通过formbuilder制作单选按钮。

我在实体中有整数列。

需要1-5的数字。

起初我试过这个。

$form = $this->createFormBuilder($myEntity)
    ->add('point',"choice",array(
        'data' => array(
            '1' => '1',
            '2' => '2',
            '3' => '3',
            '4' => '4',
            '5' => '5' 
        ),multiple => 'false'
    ))

它显示列表框而不是单选按钮。 我该如何制作单选按钮?

1 个答案:

答案 0 :(得分:2)

您需要使用expanded => true才能让单选按钮在choices选项中添加您的选择数组而不是数据选项

$form = $this->createFormBuilder($myEntity)
             ->add( 'point', "choice", array(
                 'choices'  => array(
                     '1' => '1',
                     '2' => '2',
                     '3' => '3',
                     '4' => '4',
                     '5' => '5'
                 )
             ,'expanded' => true
));