Symfony2: Storing users, roles, role hierarchy, and access controls in database Symfony2: Storing users, roles, role hierarchy, and access controls in database symfony symfony

Symfony2: Storing users, roles, role hierarchy, and access controls in database


Perhaps you might want to have a look at FOSUserBundle


The solution:

The following cookbook entry is about storing/retrieving users and roles to/from the database"How to load Security Users from the Database (the Entity Provider)"http://symfony.com/doc/current/cookbook/security/entity_provider.html

To make the long story short, your role and user entity classes have to implement RoleInterface and UserInterface / AdvancedUserInterface and you have to make some changes to your security.yml


You would need to put the roles in the db, and map it using a many-to-many relation. Then build some admin on the roles. I wrote how to change the User to use m2m roles at http://blog.jmoz.co.uk/symfony2-fosuserbundle-role-entities. I haven't got as far as the role hierarchy so that is still stored in the config.