I'm playing a little with doctrine and symfony and i encountered a problem with this model. I setup a base class ( entity ) and then a child class ( entity ), so far everything works smooth after that i wanted to add more fields to my table and i used doctrine:generate:entities BundleName. And here is the problem. If i do not set the variables from base class to protected symfony / doctrine says it cannot access that variable but if i set it as protected and generate the entities again it creates getters and setters for the protected variables from base class in my child class which i find it weird so i googled a little but i only found one topic about this problem and didn't had an answer for it. The Base Class got set the annotation MappedSuperclass but .. didn't had any effect on it.
Base class which implements AdvancedUserInterface
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
/**
* @ORM\MappedSuperclass
*/
class BaseUser implements AdvancedUserInterface
{
/**
* @var string
* @ORM\Column(name="username", type="string", length=255, nullable=true)
*/
protected $username;
/**
* @var string
* @ORM\Column(name="password", type="string", length=255)
*/
protected $password;
/**
* @var bool
* @ORM\Column(name="isActive", type="boolean")
*/
protected $isActive = '0';
/**
* [$isAccountNonExpired description].
*
* @var bool
* @ORM\Column(name="isAccountNonExpired", type="boolean")
*/
protected $isAccountNonExpired = '1';
/**
* [$isAccountNonLocked description].
*
* @var bool
* @ORM\Column(name="isAccountNonLocked", type="boolean")
*/
protected $isAccountNonLocked = '0';
/**
* [$isCredentialsNonExpired description].
*
* @var bool
* @ORM\Column(name="isCredentialsNonExpired", type="boolean")
*/
protected $isCredentialsNonExpired = '0';
/**
* 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 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;
}
/**
* USER INTERFACE IMPLEMENTATION.
*/
public function getSalt()
{
// you *may* need a real salt depending on your encoder
// see section on salt below
}
public function getRoles()
{
return array('ROLE_ADMIN');
}
public function eraseCredentials()
{
return $this->plainPassword = null;
}
/**
* ADVANCED USER INTERFACE IMPLEMENTATION.
*/
/**
* Checks whether the user's account has expired.
*
* Internally, if this method returns false, the authentication system
* will throw an AccountExpiredException and prevent login.
*
* @return bool true if the user's account is non expired, false otherwise
*
* @see AccountExpiredException
*/
public function isAccountNonExpired()
{
return $this->isAccountNonExpired;
}
/**
* Checks whether the user is locked.
*
* Internally, if this method returns false, the authentication system
* will throw a LockedException and prevent login.
*
* @return bool true if the user is not locked, false otherwise
*
* @see LockedException
*/
public function isAccountNonLocked()
{
return $this->isAccountNonLocked;
}
/**
* Checks whether the user's credentials (password) has expired.
*
* Internally, if this method returns false, the authentication system
* will throw a CredentialsExpiredException and prevent login.
*
* @return bool true if the user's credentials are non expired, false otherwise
*
* @see CredentialsExpiredException
*/
public function isCredentialsNonExpired()
{
return $this->isCredentialsNonExpired;
}
/**
* Checks whether the user is enabled.
*
* Internally, if this method returns false, the authentication system
* will throw a DisabledException and prevent login.
*
* @return bool true if the user is enabled, false otherwise
*
* @see DisabledException
*/
public function isEnabled()
{
return $this->isActive;
}
/**
* Set isActive
*
* @param boolean $isActive
* @return BaseUser
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* @return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Set isAccountNonExpired
*
* @param boolean $isAccountNonExpired
* @return BaseUser
*/
public function setIsAccountNonExpired($isAccountNonExpired)
{
$this->isAccountNonExpired = $isAccountNonExpired;
return $this;
}
/**
* Get isAccountNonExpired
*
* @return boolean
*/
public function getIsAccountNonExpired()
{
return $this->isAccountNonExpired;
}
/**
* Set isAccountNonLocked
*
* @param boolean $isAccountNonLocked
* @return BaseUser
*/
public function setIsAccountNonLocked($isAccountNonLocked)
{
$this->isAccountNonLocked = $isAccountNonLocked;
return $this;
}
/**
* Get isAccountNonLocked
*
* @return boolean
*/
public function getIsAccountNonLocked()
{
return $this->isAccountNonLocked;
}
/**
* Set isCredentialsNonExpired
*
* @param boolean $isCredentialsNonExpired
* @return BaseUser
*/
public function setIsCredentialsNonExpired($isCredentialsNonExpired)
{
$this->isCredentialsNonExpired = $isCredentialsNonExpired;
return $this;
}
/**
* Get isCredentialsNonExpired
*
* @return boolean
*/
public function getIsCredentialsNonExpired()
{
return $this->isCredentialsNonExpired;
}
}
And child class
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Gedmo\Mapping\Annotation as Gedmo;
use AppBundle\Entity\BaseUser;
/**
* User
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="Zenith\UserBundle\Entity\UserRepository")
* @UniqueEntity(fields="email", message="Email already taken")
* @UniqueEntity(fields="username", message="Username already taken")
*/
class User extends BaseUser
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=255)
* @Assert\Email()
* @Assert\NotBlank()
*/
private $email;
/**
* @var string
* @Assert\NotBlank()
* @Assert\Length(max = 4096)
*/
protected $plainPassword;
/**
* Date when the user needs to change his password
* for security reasons.
*
* @var datetime
*
* @ORM\Column(name="credentialsExpireAt", type="datetime", nullable=true)
*/
private $credentialsExpireAt;
/**
* Date when the account expires
* This can be used for temporary accounts.
*
* @var datetime
*
* @ORM\Column(name="accountExpireAt", type="datetime", nullable=true)
*/
private $accountExpireAt;
/**
* Saves last login date of the user.
*
* @var datetime
* @ORM\Column(name="lastLogin", type="datetime", nullable=true)
*/
private $lastLogin;
/**
*
*
* @ORM\Column(name="createdAt", type="datetime")
* @Gedmo\Timestampable(on="create")
*
* @var datetime
*/
private $createdAt;
/**
* @ORM\Column(name="editedAt", type="datetime")
* @Gedmo\Timestampable(on="update")
*
* @var datetime
*/
private $editedAt;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* 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 credentialsExpireAt
*
* @param \DateTime $credentialsExpireAt
* @return User
*/
public function setCredentialsExpireAt($credentialsExpireAt)
{
$this->credentialsExpireAt = $credentialsExpireAt;
return $this;
}
/**
* Get credentialsExpireAt
*
* @return \DateTime
*/
public function getCredentialsExpireAt()
{
return $this->credentialsExpireAt;
}
/**
* Set accountExpireAt
*
* @param \DateTime $accountExpireAt
* @return User
*/
public function setAccountExpireAt($accountExpireAt)
{
$this->accountExpireAt = $accountExpireAt;
return $this;
}
/**
* Get accountExpireAt
*
* @return \DateTime
*/
public function getAccountExpireAt()
{
return $this->accountExpireAt;
}
/**
* Set lastLogin
*
* @param \DateTime $lastLogin
* @return User
*/
public function setLastLogin($lastLogin)
{
$this->lastLogin = $lastLogin;
return $this;
}
/**
* Get lastLogin
*
* @return \DateTime
*/
public function getLastLogin()
{
return $this->lastLogin;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
* @return User
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* Set editedAt
*
* @param \DateTime $editedAt
* @return User
*/
public function setEditedAt($editedAt)
{
$this->editedAt = $editedAt;
return $this;
}
/**
* Get editedAt
*
* @return \DateTime
*/
public function getEditedAt()
{
return $this->editedAt;
}
}