symfony - Change role of one user no working with Symfony2 -


sorry if question has been asked many times didn't found solution on web. so, have installed fosuserbundle , i've created 2 users on application console. problem don't have role. in on controller, user entity , y set role when try access page restricted admin, says access denied. moreover, roles has no changed on databse. code in controller :

$user = $this->container->get('security.context')->gettoken()->getuser(); $user->setroles('role_admin'); if (!$this->get('security.context')->isgranted('role_admin')){     throw new accessdniedexception('access denied !'); } 

anyone have idea ? in advance !

it bad practice set user role in controller if want keep them away controller in first place. hope use line of code testing only.

the fosuserbundle provides number of command line utilities manage application's users.

the 1 need is:

$ php app/console fos:user:promote testuser role_admin

replace testuser username.

did define roles in firewall?


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -