Forms symfony 3表单实体返回转换错误

Forms symfony 3表单实体返回转换错误,forms,symfony,entity,Forms,Symfony,Entity,我的表单返回以下错误: 执行“更新用户信息集”时发生异常 居住国,想要孩子,薪水?其中id=?' 使用参数[{},a,0,22]: 可捕获的致命错误:类AppBundle\Entity\Country的对象无法捕获 不能转换为字符串 我的用户信息类型: <?php // src/AppBundle/Form/UserInfoType.php namespace AppBundle\Form; use Symfony\Component\Form\AbstractType; use Sym

我的表单返回以下错误:

执行“更新用户信息集”时发生异常 居住国,想要孩子,薪水?其中id=?' 使用参数[{},a,0,22]:

可捕获的致命错误:类AppBundle\Entity\Country的对象无法捕获 不能转换为字符串

我的用户信息类型:

<?php
// src/AppBundle/Form/UserInfoType.php
namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; 

class UserInfoType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('first_name', TextType::class, array('label' => 'Prénom'))
            ->add('surname', TextType::class, array('label' => 'Nom'))
            ->add('nationality', TextType::class, array('label' => 'Nationalité'))
            ->add('country_of_residence', EntityType::class, array(
                'class' => 'AppBundle:Country',
                'choice_label' => 'name',                   
            ))
            ->add('maritial_status', TextType::class, array('label' => 'Votre statut maritial'))
            ->add('ethnique_origin', TextType::class, array('label' => 'Origine ethinique'))
            ->add('spoken_language', TextType::class, array('label' => 'Langues parlés'))
            ->add('children', TextType::class, array('label' => 'Possèdez vous des enfants'))
            ->add('want_children', TextType::class, array('label' => 'Désirez vous des enfants'))
            ->add('astrological_sign', TextType::class, array('label' => 'Votre signe astrologique'))
            ->add('education', TextType::class, array('label' => 'Votre niveau d\'étude'))
            ->add('profession', TextType::class, array('label' => 'Votre profession'))
            ->add('salary', TextType::class, array('label' => 'Votre salaire'))
            ->add('save', SubmitType::class, array('label' => 'Suivant'))
        ;

    }
它似乎试图将整个实体传递给形式,而不仅仅是选择结果

有人知道我做错了什么吗


Thx

如果用户信息是一个实体,您是否已将居住国字段设置为国家实体上的一对一关系

好的,我在UserInfo中找到了错误

我没有在@ORM前加前缀,也没有到国家实体的正确路径,因为它不在同一名称空间中

之前:

 /**
 * One Product has One Shipping.
 * @OneToOne(targetEntity="Country")
 * @JoinColumn(name="countryOfResidence", referencedColumnName="id")
 */
private $countryOfResidence;
之后:

/**
     * One Product has One Shipping.
     * @ORM\OneToOne(targetEntity="AppBundle\Entity\Country")
     * @ORM\JoinColumn(name="countryOfResidence", referencedColumnName="id")
     */
    private $countryOfResidence;

谢谢你给我指出了正确的方向。

我也遇到了同样的错误。在我的例子中,它是“拥有”实体中的错误注释

在发生错误之前:

/** 
 * @ORM\OneToOne(targetEntity="RfpMatchBundle\Entity\Address", cascade={"persist"})
 * @ORM\Column(nullable=true, unique=false)
 */
private $address;
后固定:


您的用户或用户信息实体是什么样子的?谢谢,@Yex777,这帮助我更快地找到了答案。
/**
     * One Product has One Shipping.
     * @ORM\OneToOne(targetEntity="AppBundle\Entity\Country")
     * @ORM\JoinColumn(name="countryOfResidence", referencedColumnName="id")
     */
    private $countryOfResidence;
/** 
 * @ORM\OneToOne(targetEntity="RfpMatchBundle\Entity\Address", cascade={"persist"})
 * @ORM\Column(nullable=true, unique=false)
 */
private $address;
/** 
 * @ORM\OneToOne(targetEntity="RfpMatchBundle\Entity\Address", cascade={"persist"})
 */
private $address;`