Skip to content
Advertisement

Symfony/Doctrine/authentication, I can’t recover the roles

I have a problem when i want to connect. Let me explain, I have two User and Role entities that are linked to a ManyToMany relationship, so I have a dynamic user_role table. I would like to connect with the user who has the ROLE_ADMIN but the problem is that I cannot read the object so that it reads this role. This shows me this error.

Warning: Illegal offset type in isset or empty

I think the problem comes from the line “$ role = $ this-> roles-> toArray ();” in getRoles.

Here is the code for User.php

JavaScript

And here is the code for Role.php

JavaScript

then in my controller I did a findAll

JavaScript

var_dump($role)

JavaScript

Here is the user list code:

JavaScript

I would like to retrieve the role store in the role table.

If any of you can enlighten me, thank you in advance.

Advertisement

Answer

With little help, Here is the solution

JavaScript

And the code for the twig

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement