문제

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.

According to the question in Multiple roles required for same url in symfony 2 the entry below should allow either role access.

- { 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?

도움이 되었습니까?

해결책

This is the way to go and what i'm using:

- { path: ^/admin, roles: [ROLE_ADMIN, ROLE_TEACHER] }

다른 팁

You can use the role hierarchy in 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 ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top