php 树枝:如果 is_granted('ROLE_MANAGER') 检查未被授予
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31319773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Twig: if is_granted('ROLE_MANAGER') check is not granted
提问by Raphael_b
I want to check if a role is not granted. I have to display something only for USER but MANAGER is the hierarchy above.
我想检查是否未授予角色。我必须只为 USER 显示一些东西,但 MANAGER 是上面的层次结构。
To get that I am doing:
为了得到我正在做的事情:
{% if is_granted('ROLE_MANAGER') %}
{% else %}
my message
{% endif %}
Which is not really nice. What can be the correct syntax for:
这不是很好。什么是正确的语法:
{% if is_NOT_granted('ROLE_MANAGER') %}
ideas?
想法?
回答by MouradK
Or again
或者再次
{% if not is_granted('ROLE_MANAGER') %}
my message
{% endif %}
回答by Matteo
You can simply check as follow:
您可以简单地检查如下:
{% if is_granted('ROLE_MANAGER') == false %}
my message
{% endif %}
Hope this help
希望这有帮助
回答by Rvanlaak
You can also use:
您还可以使用:
{{ is_granted('ROLE_MANAGER') ? 'true message' : 'false message' }}
or to leave the true output empty:
或将真正的输出留空:
{{ is_granted('ROLE_MANAGER') == false ? 'false message' }}