Your problem is that the User model in FOSUserBundle never has ROLE_USER .
FOS \ UserBundle \ Model \ UserInterface
const ROLE_DEFAULT = 'ROLE_USER';
FOS \ UserBundle \ Model \ User
public function addRole($role) { $role = strtoupper($role); if ($role === static::ROLE_DEFAULT) { return $this; } if (!in_array($role, $this->roles, true)) { $this->roles[] = $role; } return $this; } .... public function getRoles() { $roles = $this->roles; foreach ($this->getGroups() as $group) { $roles = array_merge($roles, $group->getRoles()); }
When you getRoles , add ROLE_USER by default, and when you addRole , check if the role is ROLE_USER , and then skip if that happens.
In fact, each user of your system will have ROLE_USER to find all users with a role that you can simply do SELECT u FROM StageUserBundle:User u .
qooplmao
source share