简体   繁体   中英

Fos user bundle role of user

I am using the fos user bundle and I want to add two roles role_admin and role_user.

Should I do this in the securitiy.yml ?

role_hierarchy:
        ROLE_ADMIN:       ROLE_USER

The second question is that I don't have a column for role in my User table in the database. So how can roles be handled or should I add a column role to my table? More precisely : If I don't add an attribute to the entity User indicating the role, how could we know it?

Yes, if you want to add some roles for your user, you have to do it into security.yml

However, if you correctly extended FOSUserBundle (by creating a User entity that extends FOSUserBundle baseUser class) you should have that column into your db schema.

Moreover, remember that FOSUserBundle provides CLI facilities for add role to a particular user, once you've created the user you want to use, and when you've created role into security.yml file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM