Symfony 嵌入表单和EntityType多个

Symfony 嵌入表单和EntityType多个,symfony,Symfony,我有嵌入表单,在嵌入表单中有一个EntityType,它的multiple=>true。 当我保存到数据库时,我得到以下信息:条令\公共\集合\ArrayCollection@000000... 当我将EntityType更改为CHoiceType with multiple=>true时,一切似乎都是正确的 /** * Set emotions * * @param simple_array $emotions * * @return Movies */ public functi

我有嵌入表单,在嵌入表单中有一个EntityType,它的multiple=>true。 当我保存到数据库时,我得到以下信息:条令\公共\集合\ArrayCollection@000000...

当我将EntityType更改为CHoiceType with multiple=>true时,一切似乎都是正确的

/**
 * Set emotions
 *
 * @param simple_array $emotions
 *
 * @return Movies
 */
public function setEmotions($emotions) {
$this->emotions = $emotions;

return $this;
}
模板

->add('emotions', EntityType::class, array(
'class' => 'MovieBundle:Emotions',
'multiple' => true, 
'choice_label' => 'emotion',
))

我不知道问题出在哪里。是嵌入表单还是我需要数据转换器?

当您将multiple设置为true symfony将属性值设置为数组时,如果将multiple设置为false,则此属性将按原样设置,因此它们之间的区别是:

  • multiple:true将在类中调用setter此setter应该有一个数组参数,如
    setEmotions(ArrayCollection$emotions)
    ,并将使用循环逐个持久化
  • multiple:false将使用类型为Emotion的参数调用类中的setter,例如
    setEmotions(Emotion$Emotion)
    ,并且它将仅保留他从
    getEmotions()获得的对象
    在这种情况下,他将只保留doctrinearray集合,而不是包装在其中的对象,这就是异常的原因

您可以添加一个示例吗?Symfony的文档非常薄弱