我应该如何修改security.yml以实现这种情况?
情景:
student
,lecturer
和manager
可以访问lecturer
和manager
可以访问manager
可以访问我应该运行哪个确切的命令来创建相应的用户?
我读了documentation和this post,但我感到困惑!
的routing.yml
home:
path: /
admin:
path: /admin
admin_private:
path: /admin/private
应用/配置/ security.yml
security:
role_hierarchy:
ROLE_STUDENT: ?????????
ROLE_LECTURER: ????????????
ROLE_MANAGER: ???????
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, role: ????????? }
- { path: ^/admin, role: ????????? }
- { path: ^/admin/private, role: ?????????? }
答案 0 :(得分:1)
我认为您的security.yml
看起来像这样:
security:
role_hierarchy:
ROLE_LECTURER: [ROLE_STUDENT]
ROLE_MANAGER: [ROLE_LECTURER]
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, role: ROLE_STUDENT }
- { path: ^/admin, role: ROLE_LECTURER }
- { path: ^/admin/private, role: ROLE_MANAGER }
您可以创建每个用户并为其提升角色:
$ php app/console fos:user:create student
$ php app/console fos:user:promote student ROLE_STUDENT
$ php app/console fos:user:create lecturer
$ php app/console fos:user:promote lecturer ROLE_LECTURER
# ... etc.