hola Maycol. Gracias por responder.
A continuación pongo el código de las entidades usuario y roles.
Role
Código PHP:
Ver original<?php
// symfony/src/Unid/OtcBundle/Entity/Role.php
namespace Unid\OtcBundle\Entity;
use Symfony\Component\Security\Core\Role\RoleInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="admin_roles")
*/
class Role implements RoleInterface
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="nombre", type="string", length="255")
*/
protected $name;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
public function getRole() {
return $this->getName();
}
public function __toString() {
return $this->getRole();
}
}
User:
Código PHP:
Ver original<?php
// proyecto/src/Unid/OtcBundle/Entity/User.php
namespace Unid\OtcBundle\Entity;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="admin_user")
*/
class User implements UserInterface
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length="255")
*/
protected $username;
/**
* @ORM\Column(name="password", type="string", length="255")
*/
protected $password;
/**
* @ORM\Column(name="salt", type="string", length="255")
*/
protected $salt;
/**
* se utilizó user_roles para no hacer conflicto al aplicar ->toArray en getRoles()
* @ORM\ManyToMany(targetEntity="Role")
* @ORM\JoinTable(name="user_role",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
* )
*/
protected $user_roles;
public function __construct()
{
$this->user_roles = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set username
*
* @param string $username
*/
public function setUsername($username)
{
$this->username = $username;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set password
*
* @param string $password
*/
public function setPassword($password)
{
$this->password = $password;
}
/**
* 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 Unid\OtcBundle\Entity\Role $userRoles
*/
public function addRole(\Unid\OtcBundle\Entity\Role $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() {
}
}
Agradezco su ayuda y su tiempo.