0

简单的问题,但我不知道该怎么做。例如,我们有用于登录的用户实体(下面的类),我怎样才能将 $password 更改为 $accountPass ?当然,这意味着必须应用所有关系,因为它是 $password,并且所有 symfony2 类都必须理解变量(旧)$password 现在是(更改为)$accountPass。

问题是关于“变量名称”的......有人知道如何处理它吗?

用户实体:

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

/**
 * @ORM\Entity()
 * @ORM\Table(name="_account")
 * @UniqueEntity("username")
 */
class User implements UserInterface
{

public function __construct()
{
    $this->salt = md5(uniqid(null, true));
    $this->isActive = true;
}

/**
 * Get roles
 *
 * @return string 
 */
public function getRoles()
{
    return array('ROLE_USER');
}

/**
 * 
 *
 * @return 
 */
public function eraseCredentials()
{

}

/**
 * Get equals
 *
 * @return boolean
 */
public function equals(UserInterface $user)
{
    return $user->getUsername() == $this->getUsername();
}

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

/**
 * @var string
 * 
 * @ORM\Column(name="username", type="string", length=255, unique=true)
 */
protected $username;

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

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

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

/**
 * @var boolean
 * @ORM\Column(name="isActive", type="boolean")
 */
protected $isActive;

/**
 * Get id
 *
 * @return integer 
 */
public function getId()
{
    return $this->id;
}

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

    return $this;
}

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

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

    return $this;
}

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

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

    return $this;
}

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

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

    return $this;
}

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

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

    return $this;
}

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

}

4

2 回答 2

0
/**
 * @var string
 * 
 * @ORM\Column(name="password", type="string", length=255)
 */
protected $accountPass;

public function setPassword($password)
{
    $this->accountPass = $password;

    return $this;
}

/**
 * Get password
 *
 * @return string 
 */
public function getPassword()
{
    return $this->accountPass;
}

当然应该很明显,当您更改方法名称时,其他类无法知道这一点!
所有出现的旧方法名称都应更改为!

但我真的不明白你为什么要这样做?

于 2013-01-17T10:42:14.493 回答
0

检查这个答案:https ://stackoverflow.com/a/12147185/927636

您必须映射 Entity 类中的所有字段并根据需要命名它们。

于 2013-01-17T10:45:51.760 回答