In my template, I need to know if the user has a specific role to display things according to him. So far I have implemented a small function in my user class:
public function hasRole($role) { $roles = array(); foreach ($this->getRoles() as $rol) { $roles[] = $rol->getRole(); } return in_array($role, $roles); }
which tells me if this user has the role indicated by the string passed as a parameter. This work can be called from the branch template, but it does not allow me to know anything about the hierarchy of roles. Is there a way to access the role hierarchy from the controller? and directly from the twig template? I looked through the white papers and found nothing.
php symfony twig roles
Throoze
source share