I'm using Symfony2 with Sonata.
I have a list of sections on my application to which I'd like to give access to my users.
Example:
So I created 3 roles, that I can attach to users/groups (through sonata)
But as I create new sections, I'd like to have the related roles automatically listed in the admin
(without having to declare them each time in my security.yml
)
I saw sonata-admin-user does that when using the role security handler,
but I don't know how to do the same.
Finally the question is simple and is the following:
How can I add some dynamic selectable roles into my Sonata user admin bundle editor list ?
First you can load user and groups from your database. See Symfony2 cookbook Load user from database . Then in the controller of every section:
if ($this->securityContext->isGranted('Role_section1') === false) {
echo 'forbidden';
}
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.