Symfony2: Getting the list of user roles in FormBuilder

前端 未结 10 1421
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-08 15:55

I\'m making a form for user creation, and I want to give one or several roles to a user when I create him.

How do I get the list of roles defined in security.y

10条回答
  •  鱼传尺愫
    2020-12-08 16:51

    You can get a list of reachable roles from this method:

    Symfony\Component\Security\Core\Role\RoleHierarchy::getReachableRoles(array $roles)
    

    It seems to return all roles reachable from roles in array $roles parameter. It's an internal service of Symfony, whose ID is security.role_hierarchy and is not public (you must explicitely pass it as parameters, it's not acessible from Service Container).

提交回复
热议问题