简体   繁体   English

Symfony 3.3.9-app.user.roles没有获得role_admin

[英]Symfony 3.3.9 - app.user.roles doesn't get role_admin

i've a problem to get role_admin or role_user in twig. 我在获取嫩枝上的role_admin或role_user时遇到问题。

if {{ dump(app.user) }} then enter image description here 如果{{ dump(app.user) }}在此处输入图片描述

AND

if {{ dump(app.user.roles) }} then enter image description here 如果{{ dump(app.user.roles) }} 在此处输入图片描述

Then {% if is_granted('ROLE_ADMIN') %} not working So, where is the problem ? 然后{% if is_granted('ROLE_ADMIN') %}不起作用那么,问题出在哪里?

Thanks. 谢谢。

如果要检查值是否存在(与PHP中的in_array()相同):

{% if 'ROLE_ADMIN' in app.user.roles %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM