Search code examples
symfonyfosuserbundleuser-rolessymfony-3.3symfony3.x

FOS Bundle User - multiple roles


I'm exploring the possibilities of FOS Bundle User.

Thanks to Knpuniversity (https://knpuniversity.com/screencast/fosuserbundle/roles-canonical-fields) I discovered this good bundle to manage users.

In my case I also need multiple roles BUUUUUUT I don't want to save it with an array of roles in a field from user table. My intention is to use more tables with a relation 'n' to 'm' where 1 user have 'n' roles and 1 role can be used by 'n' users also.

So instead of having one table to manage users and roles, I will need one table for users, one table for roles and a last one to make the relationship n-m between them. I need that because I will use this structure for others functionalities and saving the roles as an array... will create more problems than solve... in my case.

What you propose to achieve that? Perhaps another bundle? Perhaps a simple solution to adapt the bundle to my requirements?

What do you think I could do?


Solution

  • With the FOSUserBundle indeed you can manage all kind of roles through the groups class that this bundle creates.

    In the normal flow from symfony these groups they doesn't exist by default. Its an extra feature that provides this bundle, but it helps you to manage better the roles for the users.