Ok, digging a little bit it seems that in the class SecurityContext, on the method "vote", at the moment I call "has_role" from Twig, the token is not set, so "vote" returns false because the token is null.
Does anyone know if the problem is that I can't call "has_role" from the layout or if it's a bug? Thanks. On Mon, Dec 20, 2010 at 5:47 PM, Gustavo Adrian <[email protected] > wrote: > Hi all, > > I've implemented the Security component and it works like a charm. I'm just > having a problem with roles. In my layout I want to show a toolbar based on > the roles of the user. Suppose that I have this implementation of the > "getRoles" method on my User entity: > > public function getRoles() > { > $roles = array(); > if ( $this->getIsAdmin() ) > { > $roles[] = 'ROLE_IS_ADMIN'; > } > if ( $this->getWebAccess() ) > { > $roles[] = 'ROLE_WEB_ACCESS'; > } > return $roles; > } > > > I've used this to try the "has_role" function with Twig on my layout, but > it doesn't return any role, even if the user has both properties setted. I > use the "has_role" function like this:: > > {% if has_role( 'ROLE_IS_ADMIN' ) %} 'admin' {% elseif has_role( > 'ROLE_WEB_ACCESS' ) %} 'web_access' {% else %} '' {% endif %} > > In this case, it always end with '' . > > > the "getRoles" method is supposed to return an array of strings with the > roles associated with the User? if that's so, what could be wrong with this > implementation? > > > > BTW, I've updated my vendors today. > > > Thanks. > -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en
