1
我们使用的是FOSRestBundle
。假设我想通过API来创建Ticket
对象与以下JSON体:Symfony 3形式与FOSRestBundle实体的集合
{
"title": "I need help",
"symptoms": [1, 4, 6]
"author": 31
}
作者和症状阵列在数据库中引用的主键。
我的表单建筑看起来像:
$builder->add('title', TextType::class);
$builder->add('author', EntityType::class, [
'class' => User::class
]);
$builder->add('symptoms', CollectionType::class, [
'entry_type' => EntityType::class,
'entry_options' => [
'class' => Symptom::class,
],
]);
的问题是,title
和author
被正确地分配给票据对象但symptoms
数组不转化为实体的集合。此外还有一个错误,即This form should not contain extra fields
。
如果我想将一个实体集合分配给一个对象,表单构建器应该是什么样子?