Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony2表中的输入收音机_Php_Symfony - Fatal编程技术网

Php Symfony2表中的输入收音机

Php Symfony2表中的输入收音机,php,symfony,Php,Symfony,我有一个表单模板需要尊重,但我还没有找到使用Symfony创建此模板的最佳方法 最终的表单渲染器应如下所示(输入无线电): 因此,我创建了一个带有选择字段的FormType类,但只能使用一个标签 我试过这个: $builder ->add('quantity', 'choice', array( 'choices' => array( 50 => array('desc' => 'Description 1', 'pri

我有一个表单模板需要尊重,但我还没有找到使用Symfony创建此模板的最佳方法

最终的表单渲染器应如下所示(输入无线电):

因此,我创建了一个带有选择字段的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按行创建两个输入

我也尝试使用ChoiceList,但出现了错误“数组到字符串转换错误”

您知道构建此简单表单界面的最佳方式吗?

如中所述,使用您需要将字段更改为的
选项来显示无线字段(因为它只接受一维数组):

)

对于更高级的需求,您需要使用
choice\u list
选项,并根据or使用它

$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),
        )
    )
;
$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',
    )
)