3
votes

I'm trying to add roles to the FOSUserBundle that can be managed from the database. I've read the documentation and started working on it but whatever I try it doesn't seem to work.

Main problem: FosUserBundle\Model\User and FosUserBundle\Model\UserInterface define the roles as being an array. I want to convert them to being an ArrayCollection / RoleInterface.

First attempt: Override by using Acme\UserBundle\Entity\User which extends FOSUserBundle\Model\User. But that doesn't work because I cant override the role functions that are defined in the interface.

Second attempt: Replacing the FOS User and Userinterface models which allows me to create the functions and database structure but leaves me with another problem. When I do that everything in the FOSUserBundle that references to the FOSUserBundle\Model\UserInterface will fail to work which would mean I have to override almost the entire bundle which doesn't seem like something you would want to do just to add roles.

So basically the question: how do I add database roles to the FOSUserBundle without having to override the entire bundle?

1

1 Answers

-1
votes

You can add everything just use

$user->addRole('ROLE_XXXXX');

but you must define ROLE_XXX in security.yml Nb: when you define role you must start by ROLE_YOURROLE

After if you extend user you can define new function

public function ListRole(){

         foreach($this->getRoles() as $role){

         }
}