我正在创建一个Symfony API。我有以下表单类型来接受JSON请求正文:
$builder
->add('email', Type\EmailType::class)
->add('username', Type\TextType::class)
->add('name', Type\TextType::class)
->add('plainPassword', Type\RepeatedType::class, array(
'type' => Type\PasswordType::class,
'invalid_message' => 'The password fields must match.',
))
->add('types', Type\ChoiceType::class, [
'choices' => [
'Photographer' => 'Photographer',
],
'expanded' => false,
'multiple' => true
])
;
我发送JSON Body就像这样:
{"username": "merchant2", "email": "merchant2@gmail.com", "plainPassword": {"first": "gerlie" , "second": "gerlie"}, "name": "merchant2", "types": ["Photographer"]}
表单然后验证它有错误告诉我:
您选择的值不是有效选择。
这是由ConstraintValidationExcetption引起的。
请注意,我的实体也是如此断言:
/**
* @Assert\Choice({"Event Organizer", "Photographer", "Host", "Catering", "Band", "Others"})
*/
private $types;
为什么会这样?
谢谢!