Symfony2用户实体更改类变量

时间:2013-01-17 10:21:02

标签: variables symfony entity

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

问题是关于“变量的名称”......任何人都知道如何处理它?<​​/ p>

用户实体:     

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;
}

}

2 个答案:

答案 0 :(得分: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;
}

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

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

答案 1 :(得分:0)

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

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