我有一个表单,它显示一个下拉菜单,从params.yml中定义的数组中选择一个值。
下拉列表将“0”显示为要选择的值列表上的optgroup标签。
我如何摆脱这个默认标签?
发布于 2014-12-09 01:15:48
您可以将默认的OptGroup替换为如下所定义的“标准小时”和“其他小时”。
$category_choices = array(
'Standard Hours' => array(
2 => '2',
4 => '4',
6 => '6',
8 => '8'
),
'Other Hours' => array(
1 => '1',
3 => '3',
5 => '5',
7 => '7',
9 => '9',
10 => '10'
)
);
$builder
->add('hours', 'choice', array(
'choices' => $category_choices
));或者,如果您根本不需要OptGroup标签,并且只需要可选择的条目,则可以跳过嵌套数组。
$builder
->add('hours', 'choice', array(
'choices' => array(
1 => '1',
2 => '2',
3 => '3',
4 => '4'
)
));在你的情况下,你想要的是:
$builder
->add('hours', 'choice', array(
'choices' => arrayFromParamsYML
));https://stackoverflow.com/questions/24569279
复制相似问题