Symfony 2 - Loading roles from database

前端 未结 2 1792
迷失自我
迷失自我 2021-02-06 13:05

My roles are stored in the database and I am trying to load them dynamically upon login. What I\'m doing is querying for the roles and setting them on the user object in my user

2条回答
  •  一个人的身影
    2021-02-06 13:13

    It looks like you may not be aware of the built in role management that Symfony offers. Read the docs - Managing roles in the database It is actually quite simple to do what you want, all you need to do is implement an interface and define your necessary function. The docs I linked to provide great examples. Take a look.

    UPDATE

    It looks like the docs don't give you the use statement for the AdvancedUserInterface. Here it is:

    // in your user entity
    use Symfony\Component\Security\Core\User\AdvancedUserInterface;
    

    then in your role entity:

    use Symfony\Component\Security\Core\Role\RoleInterface;
    

    The docs show you how to do the rest.

    UPDATE

    Take a look at this blog post, which shows how to create roles dynamically:

    Dynamically create roles

提交回复
热议问题