[英]Symfony granting path access to multiple roles in security.yml
Hi I would like to be able to allow access to a path in security.yml
based on the user either having ROLE_TEACHER
, or ROLE_ADMIN
. 您好我希望能够允许访问
security.yml
的路径,具体取决于具有ROLE_TEACHER
或ROLE_ADMIN
的用户。
According to the question in Multiple roles required for same url in symfony 2 the entry below should allow either role access. 根据symfony 2中相同网址所需的多个角色中的问题,下面的条目应允许任一角色访问。
- { path: ^/admin, roles: ROLE_ADMIN}
- { path: ^/admin, roles: ROLE_TEACHER}
However, this will only allow the top role access. 但是,这只允许顶级角色访问。 Is there a way of having multiple role access to a single path?
有没有办法让多个角色访问单个路径?
这是要走的路和我正在使用的方式:
- { path: ^/admin, roles: [ROLE_ADMIN, ROLE_TEACHER] }
You can use the role hierarchy in security.yml
: 您可以在
security.yml
使用角色层次结构:
role_hierarchy:
ROLE_ADMIN: [ROLE_TEACHER]
#...
access_control:
- { path: ^/admin, roles: ROLE_TEACHER}
So all of this roles will have access to that path. 因此,所有这些角色都可以访问该路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.