Drupal条件PHP如果管理员或用户有一定的角色 [英] Drupal Conditional PHP if admin or user has certain role
本文介绍了Drupal条件PHP如果管理员或用户有一定的角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果用户是管理员,以下将做些什么。
The following will do 'something' if the user is admin.
<?php if (($is_admin)) : ?>
do something
<?php endif; ?>
如何更改此项目,如果用户是管理员或具有某些角色?
感谢
How can I change this so 'something' will happen if the user is admin or has a certain role? Thanks
推荐答案
角色存储在 $ user-> roles
。要检查用户是管理员还是具有某一角色,您可以简单地:
Roles are stored in $user->roles
. To check "if the user is admin or has a certain role" you can simply:
if ($is_admin || in_array('some_role', $user->roles)):
这篇关于Drupal条件PHP如果管理员或用户有一定的角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文