我想消除 FOSUserBundle 中对用户名的需求。我的用户将仅使用电子邮件地址登录,并且我已将真实姓名字段添加为用户实体的一部分。我意识到我需要重做这里描述的整个映射。 我想我做得对,但是当我尝试提交注册表时,我得到了错误:
“只有 Doctrine 映射的字段名称才能验证唯一性。”
奇怪的是,我没有尝试对用户实体中的任何内容断言唯一约束。
这是我的完整用户实体文件:
<?php
// src/MyApp/UserBundle/Entity/User.php
namespace MyApp\UserBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="depbook_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank(message="Please enter your first name.", groups={"Registration", "Profile"})
* @Assert\MaxLength(limit="255", message="The name is too long.", groups={"Registration", "Profile"})
*/
protected $firstName;
/**
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank(message="Please enter your last name.", groups={"Registration", "Profile"})
* @Assert\MaxLength(limit="255", message="The name is too long.", groups={"Registration", "Profile"})
*/
protected $lastName;
/**
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank(message="Please enter your email address.", groups={"Registration", "Profile"})
* @Assert\MaxLength(limit="255", message="The name is too long.", groups={"Registration", "Profile"})
* @Assert\Email(groups={"Registration"})
*/
protected $email;
/**
* @ORM\Column(type="string", length=255, name="email_canonical", unique=true)
*/
protected $emailCanonical;
/**
* @ORM\Column(type="boolean")
*/
protected $enabled;
/**
* @ORM\Column(type="string")
*/
protected $salt;
/**
* @ORM\Column(type="string")
*/
protected $password;
/**
* @ORM\Column(type="datetime", nullable=true, name="last_login")
*/
protected $lastLogin;
/**
* @ORM\Column(type="boolean")
*/
protected $locked;
/**
* @ORM\Column(type="boolean")
*/
protected $expired;
/**
* @ORM\Column(type="datetime", nullable=true, name="expires_at")
*/
protected $expiresAt;
/**
* @ORM\Column(type="string", nullable=true, name="confirmation_token")
*/
protected $confirmationToken;
/**
* @ORM\Column(type="datetime", nullable=true, name="password_requested_at")
*/
protected $passwordRequestedAt;
/**
* @ORM\Column(type="array")
*/
protected $roles;
/**
* @ORM\Column(type="boolean", name="credentials_expired")
*/
protected $credentialsExpired;
/**
* @ORM\Column(type="datetime", nullable=true, name="credentials_expired_at")
*/
protected $credentialsExpiredAt;
public function __construct()
{
parent::__construct();
// your own logic
}
/**
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* @return string
*/
public function getLastName()
{
return $this->lastName;
}
/**
* Sets the first name.
*
* @param string $firstname
*
* @return User
*/
public function setFirstName($firstname)
{
$this->firstName = $firstname;
return $this;
}
/**
* Sets the last name.
*
* @param string $lastname
*
* @return User
*/
public function setLastName($lastname)
{
$this->lastName = $lastname;
return $this;
}
}
我已经看到了有关此的各种建议,但似乎没有一个建议对我有用。FOSUserBundle 文档对于什么必须是非常常见的请求非常少见。