如何获取当前登录的角色symfony?

how to get the currently logged in role symfony?

我想获取当前登录用户的角色。因为我想在我的导航栏中显示有人可以帮助我吗?

我的问题是如何获得当前角色

如果我没记错的话,你可以通过 {{ app.user && app.user.roles }} 在 twig 中获得角色,但你会获得一系列角色。

希望对您有所帮助。

你可以从当前用户获取,当我们获取角色时,它是returns角色数组

$user = $this->getUser();
$role = $user->getRoles();

在树枝上

{{app.user.roles}}