Foros del Web » Programando para Internet » PHP » Symfony »

[SOLUCIONADO] Problema al loguearme en mi app

Estas en el tema de Problema al loguearme en mi app en el foro de Symfony en Foros del Web. Ya solo me queda hacer el panel de administración y estará finiquitada, pero me falla al querer entrar en el panel, este es el error ...
  #1 (permalink)  
Antiguo 11/11/2015, 16:31
 
Fecha de Ingreso: septiembre-2015
Mensajes: 71
Antigüedad: 8 años, 7 meses
Puntos: 0
Problema al loguearme en mi app

Ya solo me queda hacer el panel de administración y estará finiquitada, pero me falla al querer entrar en el panel, este es el error que me da:
FatalErrorException: Error: Call to a member function getRole() on string in /Applications/MAMP/htdocs/dipro3d/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Role/RoleHierarchy.php line 47

Esta son mis entidades:

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
{
    
/**
     * @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)
     */
    
public $username;

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

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

    
/**
     * @var string
     *
     * @ORM\Column(name="salt", type="string", length=255)
     */
    
public $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")}
     * )
     */
    
public $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() {
 
    }
}
Roles:
Código PHP:
<?php

namespace TMKAdminBundleEntity
;

use 
SymfonyComponentSecurityCoreRoleRoleInterface;
use 
DoctrineORMMapping as ORM;

/**
 * Roles
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="TMK\AdminBundle\Entity\RolesRepository")
 */
class Roles implements RoleInterface
{
    
/**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    
private $id;

    
/**
     * @var string
     *
     * @ORM\Column(name="Name", type="string", length=255)
     */
    
public $name;
    
    
/**
     * @ORM\ManyToMany(targetEntity="Users", mappedBy="user_roles")
     **/
    
public $users;

    public function 
__construct() {
        
$this->users = new DoctrineCommonCollectionsArrayCollection();
    }
    
    
/**
     * Get id
     *
     * @return integer 
     */
    
public function getId()
    {
        return 
$this->id;
    }

    
/**
     * Set name
     *
     * @param string $name
     * @return Roles
     */
    
public function setName($name)
    {
        
$this->name $name;
    
        return 
$this;
    }

    
/**
     * Get name
     *
     * @return string 
     */
    
public function getName()
    {
        return 
$this->name;
    }
    
    public function 
getRole() {
        return 
$this->getName();
    }
 
    public function 
__toString() {
        return 
$this->getRole();
    }
}
  #2 (permalink)  
Antiguo 12/11/2015, 11:48
 
Fecha de Ingreso: septiembre-2015
Mensajes: 71
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: Problema al loguearme en mi app

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 UserInterfaceSerializable
{
    
/**
     * @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
  #3 (permalink)  
Antiguo 14/11/2015, 10:29
 
Fecha de Ingreso: septiembre-2015
Mensajes: 71
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: Problema al loguearme en mi app

Lo arregle buscando info en internet y cambiando unas cosas en unos archivos que al parecer tenían un bug

Etiquetas: app
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:22.