當我想在Symfony上使用FOSUserBundle登錄時,我不斷收到錯誤標題。問題是,我已經從我的數據庫中爲我的用戶表創建了一個「id」,所以我不想像他們在FOSUserBundle指南中所要求的那樣創建一個「id」字段。我不明白爲什麼當我的代碼中沒有更多的「id」字段時會給我這個錯誤。無法識別的ID字段與Symfony 3和FOSUserBundle
這個「id」字段是強制性的嗎?
這裏是我的User類(這裏稱爲「Utilisateurs」)使用Doctrine \ ORM \ Mapping作爲ORM的代碼; 使用FOS \ UserBundle \ Model \ User作爲BaseUser;
/**
* Utilisateurs
*
* @ORM\Table(name="utilisateurs", indexes={@ORM\Index(name="FK_UTILISATEURS_id_sexe", columns={"id_sexe"}), @ORM\Index(name="FK_UTILISATEURS_id_niveau", columns={"id_niveau"})})
* @ORM\Entity
*/
class Utilisateurs extends BaseUser
{
public function __construct()
{
parent::__construct();
}
/**
* @var string
*
* @ORM\Column(name="nom", type="string", length=25, nullable=true)
*/
private $nom;
/**
* @var string
*
* @ORM\Column(name="prenom", type="string", length=25, nullable=true)
*/
private $prenom;
/**
* @var \DateTime
*
* @ORM\Column(name="date_naissance", type="date", nullable=true)
*/
private $dateNaissance;
/**
* @var string
*
* @ORM\Column(name="url_photo", type="string", length=100, nullable=true)
*/
private $urlPhoto;
/**
* @var integer
*
* @ORM\Column(name="id_utilisateur", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $idUtilisateur;
/**
* @var \Site\UserBundle\Entity\Sexes
*
* @ORM\ManyToOne(targetEntity="Site\UserBundle\Entity\Sexes")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_sexe", referencedColumnName="id_sexe")
* })
*/
private $idSexe;
/**
* @var \Site\UserBundle\Entity\Niveaux
*
* @ORM\ManyToOne(targetEntity="Site\UserBundle\Entity\Niveaux")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_niveau", referencedColumnName="id_niveau")
* })
*/
private $idNiveau;`
正如你可以看到我已經有一個「id_utilisateur」字段是該實體的ID。 這裏是的實體信息以XML代碼:The XML Code
另外這裏的錯誤,我得到的截圖,當我嘗試登錄:The Error
謝謝我做到了,它工作正常! –