Symfony2 Catchable Fatal Error: Argument 1 passed to entity Catchable Fatal Error: Argument 1 passed to entity

Symfony2 Catchable Fatal Error: Argument 1 passed to entity Catchable Fatal Error: Argument 1 passed to entity

我遇到了这个错误,我被困了好几个小时

Catchable Fatal Error: Argument 1 passed to Thinking\ThinkBundle\Entity\InYourMind::setThinkFriend() must be an instance of Thinking\ThinkBundle\Entity\InYourMindFriend, array given, called in /var/www/html/thinkroulette/vars/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 410 and defined 

我搜索了这个问题,出现了很多结果,但我无法解决这个问题。

我正在尝试以一种形式整合两个实体,我的想法来自于此 post Create 2 different entities with same form in Symfony 2

可能这很愚蠢,但我什至无法理解错误。 :(

下面是主窗体的片段

//InYourMindType.php
    class InYourMindType extends AbstractType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder->add('thinkFriend', new InYourMindFriendType)
        //...

这是 "embedded" 形式:

//InYourMindDriendType  
class InYourMindFriendType extends AbstractType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder->add('email', 'email', array(
                'label' => 'label_think_userEmail',
                'required' => false,
                'attr' => array(
                    'title' => 'label_think_userEmail',
                    'class' => 'form-control'
                )
            ));
        }
    public function getName()
    {
        return 'thinkFriend';
    }

调用主窗体的twig(然后是嵌入的)

<div class="form-group">
    {{ form_label(t_form.title) }}
    {{ form_widget(t_form.title) }}
    {{ form_errors(t_form.title) }}
</div>
<div class="form-group">
    {{ form_label(t_form.thinkFriend.email) }}
    {{ form_widget(t_form.thinkFriend.email) }}
    {{ form_errors(t_form.thinkFriend.email) }}

这些表单属于两个不同的实体,分别通过多对一和一对多关系连接。

如果你需要我 post 实体就问。

非常感谢

为您的 InYourMindFriendType 设置 data_class 选项

结帐http://symfony.com/doc/current/reference/forms/types/form.html#data-class