Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/10/2014, 06:39
sxwark
 
Fecha de Ingreso: agosto-2013
Ubicación: Oyón/Alava
Mensajes: 23
Antigüedad: 10 años, 9 meses
Puntos: 0
Problema con Roles

Buenas a todos.

Antes de empezar dar gracias a cualquiera que me pueda hechar una mano.

He de decir que aun soy novato con symfony2 y me esta costando un poquito hacer las cosas.

Bueno expongo el problema.

Estoy intentando implementar ROLES atraves de la base de datos usando doctrine2, el problema viene cuando estoy implementando el RoleInterface y añado el metodo getRole(), Pues al iniciar sesión me devuelve un error.

He aquí el error.
Código:
FatalErrorException: Error: Call to a member function getRole() on a non-object in /home/DOMAINS/www.wolfrc.dev/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Role/RoleHierarchy.php line 43
Ahora paso a mostrar como estan las entidad y sus relaciones


Entidad Usuario:
Código PHP:
namespace WolfrcUsuarioBundleEntity;

use 
DoctrineORMMapping as ORM;
use 
SymfonyComponentSecurityCoreUserUserInterface;
use 
DoctrineCommonCollectionsArrayCollection;

/**
 * Usuario
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Wolfrc\UsuarioBundle\Entity\UsuarioRepository")
 */
class Usuario implements UserInterface
{
    
/**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    
private $id;

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

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

    
/**
     * @var string
     *
     * @ORM\Column(name="dni", type="string", length=9)
     */
    
private $dni;

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

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

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

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

    
/**
     * @var string
     *
     * @ORM\Column(name="ciudad", type="string", length=255)
     */
    
private $ciudad;
    
    
/**
     * @ORM\ManyToMany(targetEntity="Wolfrc\UsuarioBundle\Entity\Rol", inversedBy="usuarios")
     */
    
private $roles;

//    function equals(UserInterfaces $usuario)
//    {
//        return $this->$this->getEmail() == $usuario->getEmail();
//    }
    
    
public function __construct() {
        
$this->roles = new ArrayCollection();
    }
    
    
    function 
eraseCredentials()
    {
        
    }
    
    function 
getRoles()
    {
        return 
$this->roles->toArray();
    }
    
    function 
getUsername()
    {
        return 
$this->getEmail();
    }

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

    
/**
     * Set nombre
     *
     * @param string $nombre
     * @return Usuario
     */
    
public function setNombre($nombre)
    {
        
$this->nombre $nombre;

        return 
$this;
    }

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

    
/**
     * Set apellidos
     *
     * @param string $apellidos
     * @return Usuario
     */
    
public function setApellidos($apellidos)
    {
        
$this->apellidos $apellidos;

        return 
$this;
    }

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

    
/**
     * Set dni
     *
     * @param string $dni
     * @return Usuario
     */
    
public function setDni($dni)
    {
        
$this->dni $dni;

        return 
$this;
    }

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

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

        return 
$this;
    }

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

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

        return 
$this;
    }

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

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

        return 
$this;
    }

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

    
/**
     * Set direccion
     *
     * @param string $direccion
     * @return Usuario
     */
    
public function setDireccion($direccion)
    {
        
$this->direccion $direccion;

        return 
$this;
    }

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

    
/**
     * Set ciudad
     *
     * @param string $ciudad
     * @return Usuario
     */
    
public function setCiudad($ciudad)
    {
        
$this->ciudad $ciudad;

        return 
$this;
    }

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

    
/**
     * Add roles
     *
     * @param \Wolfrc\UsuarioBundle\Entity\Rol $roles
     * @return Usuario
     */
    
public function addRole(WolfrcUsuarioBundleEntityRol $roles)
    {
        
$this->roles[] = $roles;

        return 
$this;
    }

    
/**
     * Remove roles
     *
     * @param \Wolfrc\UsuarioBundle\Entity\Rol $roles
     */
    
public function removeRole(WolfrcUsuarioBundleEntityRol $roles)
    {
        
$this->roles->removeElement($roles);
    }

Entidad Rol:
Código PHP:
namespace WolfrcUsuarioBundleEntity;

use 
SymfonyComponentSecurityCoreRoleRoleInterface;
use 
DoctrineORMMapping as ORM;

/**
 * Rol
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Wolfrc\UsuarioBundle\Entity\RolRepository")
 */
class Rol implements RoleInterface
{
    
/**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    
private $id;

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

    
/**
     *
     * @ORM\ManyToMany(targetEntity="Wolfrc\UsuarioBundle\Entity\Usuario", mappedBy="roles")
     */
    
private $usuarios;
    
    
    public function 
__construct() {
        
$this->usuarios = new DoctrineCommonCollectionsArrayCollection();
    }
    
    
/**
     * Get id
     *
     * @return integer 
     */
    
public function getId()
    {
        return 
$this->id;
    }

    
/**
     * Set nombre
     *
     * @param string $nombre
     * @return Rol
     */
    
public function setNombre($nombre)
    {
        
$this->nombre $nombre;

        return 
$this;
    }

    
/**
     * Get nombre
     *
     * @return string 
     */
    
public function getNombre()
    {
        return 
$this->nombre;
    }
    
    public function 
getRole(){
        return 
$this->getNombre();
    }

    
/**
     * Add usuarios
     *
     * @param \Wolfrc\UsuarioBundle\Entity\Usuario $usuarios
     * @return Rol
     */
    
public function addUsuario(WolfrcUsuarioBundleEntityUsuario $usuarios)
    {
        
$this->usuarios[] = $usuarios;

        return 
$this;
    }

    
/**
     * Remove usuarios
     *
     * @param \Wolfrc\UsuarioBundle\Entity\Usuario $usuarios
     */
    
public function removeUsuario(WolfrcUsuarioBundleEntityUsuario $usuarios)
    {
        
$this->usuarios->removeElement($usuarios);
    }

    
/**
     * Get usuarios
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    
public function getUsuarios()
    {
        return 
$this->usuarios;
    }

Me gustaría saber porque me ha salido el error puesto que he estado investigando y no me ha dejado nada claro.

Decir que el error solamente lo lanza estando logueado.
La version de symfony es la 2.5.5

Gracias a todos los que me puedan ayudar.