2015-11-01 25 views
0

我有以下表單生成器:如何從形式訪問選擇在Symfony的

$builder->add('status', 'choice', array('attr' => array(
      'choices' => array('0' => 'Principal', '1' => 'Teacher', '2' => 'Student'), 
      'required' => true, 'expanded' => 'false', 'multiple' => 'true' 
     ))); 

如何在一個方式來呈現這3個值作爲單選按鈕在樹枝模板像下面介紹(它不工作)?

{{ form_start(form) }} 
{{ form_widget(form.status.choices[0]) }} 
{{ form_end(form) }} 

回答

2

如果你想單選按鈕,你需要更改選項'expanded' => 'true', 'multiple' => 'false'

enter image description here

在樹枝:

{{ form_start(form) }} 
{{ form_widget(form.status) }} 
{{ form_end(form) }} 

更多信息:choice Field Type