Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MappingException:在';中找不到目标实体UserBundle\entity\userRoles;UserBundle\Entity\User#userRoles';_Php_Symfony_Doctrine Orm_Fosuserbundle - Fatal编程技术网

Php MappingException:在';中找不到目标实体UserBundle\entity\userRoles;UserBundle\Entity\User#userRoles';

Php MappingException:在';中找不到目标实体UserBundle\entity\userRoles;UserBundle\Entity\User#userRoles';,php,symfony,doctrine-orm,fosuserbundle,Php,Symfony,Doctrine Orm,Fosuserbundle,我是Symfony的初学者,我被要求使用FOSUser创建一个包含一些信息的用户实体 一切都很顺利,直到我尝试执行下面的命令行 php/bin控制台原则:模式:更新--force 这时我犯了以下错误 [条令\ORM\Mapping\MappingException] 在“UserBundle\entity\User\userRoles”中找不到目标实体UserBundle\entity\userRoles 我试图更改一些注释,但因为我不知道自己在做什么,所以这并没有真正起作用 下面是实体的片段

我是Symfony的初学者,我被要求使用FOSUser创建一个包含一些信息的用户实体 一切都很顺利,直到我尝试执行下面的命令行

php/bin控制台原则:模式:更新--force

这时我犯了以下错误

[条令\ORM\Mapping\MappingException]
在“UserBundle\entity\User\userRoles”中找不到目标实体UserBundle\entity\userRoles

我试图更改一些注释,但因为我不知道自己在做什么,所以这并没有真正起作用

下面是实体的片段

<?php
// src/UserBundle/Entity/User.php
namespace UserBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @ORM\Entity
* @UniqueEntity(fields="email", message="Email already taken")
* @UniqueEntity(fields="username", message="Username already taken")
*/
class User extends BaseUser{

    /**
    * @ORM\Id
    * @ORM\Column(type="integer")
    * @ORM\GeneratedValue(strategy="AUTO")
    */
    protected $id;

//    /**
//    * @ORM\Column(type="string", length=255, unique=true)
//    * @Assert\NotBlank()
//    * @Assert\Email()
//    */
//    protected $email;

    /**
     * @var string
     *
     * @ORM\Column(name="prenom", type="string", length=255)
     */
    private $prenom;

    /**
     * @var string
     *
     * @ORM\Column(name="nom", type="string", length=255)
     */
    private $nom;

    /**
     * @var string
     *
     * @ORM\Column(name="pseudo", type="string", length=255)
     */
    private $pseudo;

    /**
     * @var string
     *
     * @ORM\Column(name="telephone", type="string", length=10)
     */
    private $telephone;

//    /**
//    *
//    * @ORM\Column(type="string", length=64)
//    */
//    protected $password;

    /**
     * @ORM\ManyToMany(targetEntity="userRoles", inversedBy="user")
     * @ORM\JoinTable(name="userRoles")
     *
     */
    private $userRoles;





    /**
     * Set prenom
     *
     * @param string $prenom
     *
     * @return User
     */
    public function setPrenom($prenom)
    {
        $this->prenom = $prenom;

        return $this;
    }

    /**
     * Get prenom
     *
     * @return string
     */
    public function getPrenom()
    {
        return $this->prenom;
    }

    /**
     * Set nom
     *
     * @param string $nom
     *
     * @return User
     */
    public function setNom($nom)
    {
        $this->nom = $nom;

        return $this;
    }

    /**
     * Get nom
     *
     * @return string
     */
    public function getNom()
    {
        return $this->nom;
    }

    /**
     * Set pseudo
     *
     * @param string $pseudo
     *
     * @return User
     */
    public function setPseudo($pseudo)
    {
        $this->pseudo = $pseudo;

        return $this;
    }

    /**
     * Get pseudo
     *
     * @return string
     */
    public function getPseudo()
    {
        return $this->pseudo;
    }

    /**
     * Set telephone
     *
     * @param string $telephone
     *
     * @return User
     */
    public function setTelephone($telephone)
    {
        $this->telephone = $telephone;

        return $this;
    }

    /**
     * Get telephone
     *
     * @return string
     */
    public function getTelephone()
    {
        return $this->telephone;
    }

    /**
     * Add userRole
     *
     * @param \UserBundle\Entity\Role $userRole
     *
     * @return User
     */
    public function addUserRole(\UserBundle\Entity\Role $userRole)
    {
        $this->userRoles[] = $userRole;

        return $this;
    }

    /**
     * Remove userRole
     *
     * @param \UserBundle\Entity\Role $userRole
     */
    public function removeUserRole(\UserBundle\Entity\Role $userRole)
    {
        $this->userRoles->removeElement($userRole);
    }

    /**
     * Get userRoles
     *
     * @return \Doctrine\Common\Collections\Collection
     */
    public function getUserRoles()
    {
        return $this->userRoles;
    }
}

您的注释中似乎有一个打字错误,与
set setter/getter方法targetEntity不是
userRoles
类,而是
UserBundle\Entity\Role

因此,将定义更改如下:

/**
 * @ORM\ManyToMany(targetEntity="UserBundle\Entity\Role", inversedBy="user")
 * @ORM\JoinTable(name="userRoles")
 *
 */
private $userRoles;
希望这有帮助