I try to assign role to user in my controller. For example in database I getting this result a:1:{i:0;s:11:"ROLE_DRIVER";}
, but when somewhere in my app I try do this
if ($securityContext->isGranted('ROLE_DRIVER')) {
I always get false. In profiler I see that current user has ROLE_USER
instead of _DRIVER
.
Where is my problem ? Here is my role assign:
$user->setRoles(array(1 => 'ROLE_DRIVER'));
User config:
# FOSUserBundle configuration
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Vputi\UserBundle\Entity\User
registration:
form:
type: vputi_user_registration
profile:
form:
type: vputi_user_profile
change_password:
form:
type: vputi_user_change_password
name: vputi_user_change_password
When in twig I do this:
{% if user.roles[0] == 'ROLE_DRIVER' %}
All works fine, but in Controller...