我尝试过,但是它允许用户选择两个选项,我只希望允许用户选择一个角色
->add("role", ChoiceType::class, [
'choices' => [
'Technician' => 'technician',
'Client' => 'client'
]
]);
发生这种情况是因为您正在使用复选框。您必须通过将选项expanded
设置为true
,将multiple
设置为false
,将它们变成单选按钮。详细信息here。
$builder->add(
'role',
ChoiceType::class, [
'expanded' => true,
'multiple' => false,
'choices' => [
'Technician' => 'technician',
'Client' => 'client'
]
]
);