我将Symfony Form组件用于我们的RESTish JSON API (灵感来自http://williamdurand.fr/2012/08/02/rest-apis-with-symfony2-the-right-way/)。
现在,我有了一些多维POST请求,它们始终具有相同的根键(name
和actions
),但具有不同的子元素。
{
"name": "Name",
"actions": [{
"type": "type_of_action",
"config": {
"name": "name",
"assigned_to": "23cb1a6b-5a99-4b91-ae72-b52882b45f47",
"information": "Lorem Impsum"
}
},{
"type": "type_of_other_action",
"config": {
"name": "name",
"dueDate": "2016-12-01"
"active": "true"
}
}]
}
如您所见,每个actions
-element上的config
都可能不同。我需要这样的东西:
->add('config', [TaskActionType::class, OtherActionType::class])
我知道,不可能呈现这样的表单,但我只需要它来验证请求并将其传输到一个可靠的数组($data = $form->get('actions')->getData()
)中。
https://stackoverflow.com/questions/44503651
复制相似问题