是/否单选按钮,用于布尔值

时间:2018-09-13 15:03:40

标签: symfony-3.4

Symfony 3中有些我不了解的东西

在我的formType.php上(其中“ cible”是布尔值):

->add('cible', ChoiceType::class, array(
    'required' => false,
    'expanded' => true,
    'choices' => array(
        'yes' => 1,
        'no' => 0
    ),
    'placeholder' => false,
))

重新调整

<select id="search_sample_to_order_cible" name="search_sample_to_order[cible]">
    <option value="1">Oui</option>
    <option value="0">Non</option>
</select>

好。但是我想要单选按钮,当我通过时将其展开为true:

   ->add('cible', ChoiceType::class, array(
        'required' => false,
        'expanded' => false,
        'choices' => array(
            'yes' => 1,
            'no' => 0
        ),
        'placeholder' => false,
    ))

no选项的值变成'1',我不想要!

<label for="search_sample_to_order_cible_0" class="radio">
    <input id="search_sample_to_order_cible_0" name="search_sample_to_order[cible]" value="1" type="radio">yes
</label>
<label for="search_sample_to_order_cible_1" class="radio">
    <input id="search_sample_to_order_cible_1" name="search_sample_to_order[cible]" value="1" type="radio">no
</label>

0 个答案:

没有答案