php - Roles assignement in Symfony 2 -


I tried to play the role of the user in your controller. For example in the database I'm getting this result one: 1: {I: 0; S: 11: "ROLE_DRIVER";} , but when you are not anywhere in my application where I try to do it

  if ($ securityContext- & gt; isGranted ( 'ROLE_DRIVER ')) { 

I always get liars. I profiler that the current user is ROE__USER instead of _DRIVER . Where's my problem? Here's my role assigned:

  $ user-> SetRoles (array (1 = & gt; 'ROLE_DRIVER'));  

User config:

  # FOSUserBundle configuration fos_user: db_driver: ORM # other valid values ​​'MongoDB', 'CouchDB' and 'Propel' firewall_name: main user_class: Vputi \ UserBundle \ unit \ user Registration: Appearance: type: vputi_user_registration profile: Appearance: type: vputi_user_profile change_password: Appearance: type: vputi_user_change_password name: vputi_user_change_password  

I do twig when:

  {% user.roles [0] == 'ROLE_DRIVER'%}  

all works fine, but the controller ... < Role_draivr

pre> $ user & gt; AddRole ('ROLE_DRIVER');

or you can change the way you are paying a price for it:

  $ user & gt; SetRoles (array ("ROLE_DRIVER")); // Update User  

Update:

  $ user-> Adrol ('ROLE_DRIVER'); $ User- & gt; AddRole ('ROLE_OLD_DRIVER');  

This is a line that is similar to set up two roles:

  $ user- & gt; Setrol (arrays ("ROLE_DRIVER", "ROLE_OLD_DRIVER"));  

Tvig Czech:

  {% if app.user.hasRole ( 'ROLE_FOO')%} ... {% endif%}  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -