Pb de string et array avec les roles d'une user
Bonjour, je suis en train d'étudier Symfony et j'avance calcmement.
Je bute sur un point précis.
J'ai un un user qui a un role defini comme suit :
Code:
1 2 3 4 5 6
| /**
* @var string
*
* @ORM\Column(name="roles", type="string", length=15)
*/
private $roles; |
Si je fait le getRoles comme suit :
Code:
1 2 3 4
| public function getRoles()
{
return $this->roles = array();
} |
Je ne visualise pas la liste des users :
An exception has been thrown during the rendering of a template ("Notice: Array to string conversion").
a cause du user.roles => par contre :
dans Dumped Contents j'ai bien un roles: "ROLES_REDACTOR".
Si je modifie le getRoles comme suit:
Code:
1 2 3 4
| public function getRoles()
{
return $this->roles;
} |
j'ai bien ma liste mais je ne peux plus me connecter :
Citation:
Type error: Argument 4 passed to Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::__construct() must be of the type array, string given, called in C:\kcc\vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider.php on line 94
in vendor\symfony\symfony\src\Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken.php (line 32)
* @param string $providerKey The provider key * @param (RoleInterface|string)[] $roles An array of roles * * @throws \InvalidArgumentException */ public function __construct($user, $credentials, $providerKey, array $roles = array())
Je tourne en rond.
Merci de votre aide