He hecho que mi clase users implemente a Serializable, pero ahora me da este error:
Warning: Erroneous data format for unserializing 'TMK\AdminBundle\Entity\Users' in /Applications/MAMP/htdocs/dipro3d/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 830
Clase users
Código PHP:
<?php
namespace TMKAdminBundleEntity;
use SymfonyComponentSecurityCoreUserUserInterface;
use DoctrineORMMapping as ORM;
/**
* Users
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="TMK\AdminBundle\Entity\UsersRepository")
*/
class Users implements UserInterface, Serializable
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="Username", type="string", length=255)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="Name", type="string", length=255)
*/
private $name;
/**
* @var string
*
* @ORM\Column(name="Password", type="string", length=255)
*/
private $password;
/**
* @var string
*
* @ORM\Column(name="salt", type="string", length=255)
*/
private $salt;
/**
*
* se utilizó user_roles para no hacer conflicto al aplicar ->toArray en getRoles()
* @ORM\ManyToMany(targetEntity="Roles", inversedBy="users")
* @ORM\JoinTable(name="user_role",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
* )
*/
private $user_roles;
public function __construct()
{
$this->user_roles = new DoctrineCommonCollectionsArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set username
*
* @param string $username
* @return Users
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set name
*
* @param string $name
* @return Users
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set password
*
* @param string $password
* @return Users
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set salt
*
* @param string $salt
*/
public function setSalt($salt)
{
$this->salt = $salt;
}
/**
* Get salt
*
* @return string
*/
public function getSalt()
{
return $this->salt;
}
/**
* Add user_roles
*
* @param TMK\AdminBundle\Entity\Role $userRoles
*/
public function addRole(TMKAdminBundleEntityRole $userRoles)
{
$this->user_roles[] = $userRoles;
}
public function setUserRoles($roles) {
$this->user_roles = $roles;
}
/**
* Get user_roles
*
* @return Doctrine\Common\Collections\Collection
*/
public function getUserRoles()
{
return $this->user_roles;
}
/**
* Get roles
*
* @return Doctrine\Common\Collections\Collection
*/
public function getRoles()
{
return $this->user_roles->toArray(); //IMPORTANTE: el mecanismo de seguridad de Sf2 requiere ésto como un array
}
/**
* Compares this user to another to determine if they are the same.
*
* @param UserInterface $user The user
* @return boolean True if equal, false othwerwise.
*/
public function equals(UserInterface $user) {
return md5($this->getUsername()) == md5($user->getUsername());
}
/**
* Erases the user credentials.
*/
public function eraseCredentials() {
}
public function serialize()
{
return serialize(array(
$this->id,
));
}
public function unserialize($serialized)
{
list (
$this->id,
) = unserialize($serialized);
}
}
A ver si alguien puede ver mi error. Gracias