2015-03-19 50 views
1

我有一个表格模板来尊重,我还没有找到与Symfony创建此的最佳方式。Symfony2输入收音机在表

最终形式渲染器应该是这样的(输入电台):

-------------------------------------- 
| ○ | Description 1 | 0 $ | 
------------------------------------- 
| ○ | Description 2 | 10 $ | 
-------------------------------------- 
| ○ | Description 3 | 50 $ | 
-------------------------------------- 
| ○ | Description n | ... | 
-------------------------------------- 

所以我创建了一个选择字段一个FormType类,但是仅仅只有一个标签是可能的。

我已经试过这样:

$builder 
    ->add('quantity', 'choice', array(
     'choices' => array(
      50 => array('desc' => 'Description 1', 'price' => 0), 
      100 => array('desc' => 'Description 2', 'price' => 10), 
      150 => array('desc' => 'Description 3', 'price' => 50), 
      200 => array('desc' => 'Description 4', 'price' => 100), 
     ) 
    ) 
; 

但它不工作,Symfony的创建两个输入的行...

我也尝试了选择列表,但我的错误“阵列到字符串转换错误”...

你知道什么是建立这个简单的表单界面的最佳方式?

回答

2

Choice field docs描述了使用choices字段你需要更改字段以显示无线电字段(因为它仅接受单维阵列):

$builder 
->add('quantity', 'choice', array(
    'expanded' => true, 
    'multiple' => false, 
    'choices' => array(
     50 => 'what you want string', 
     100 => 'what you want string', 
     150 => 'what you want string', 
     200 => 'what you want string', 
    ) 
) 

;

对于需要使用choice_list选项,并相应地使用它来ChoiceListInterfaceBuild a Custom Field

更高级的需求
相关问题