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() {
}
}
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();
}
}