[英]Redirecting a drupal user based on their role
I have a page on my website that I want to redirect users to different pages based on their role. 我的网站上有一个页面,我想根据用户的角色将用户重定向到其他页面。
I tried to make a module to put mymodule_init()
to redirect users. 我试图制作一个模块来放置
mymodule_init()
来重定向用户。
I check with arg(0)
my page but cannot figure out how to redirect user based on role. 我在页面上使用
arg(0)
检查,但无法确定如何根据角色重定向用户。
How do I? 我如何?
You can access the $user
variable since its a global variable by putting 您可以通过以下方式访问
$user
变量,因为它是全局变量:
global $user;
At the beginning of your logic. 在逻辑的开始。 Then you can check the user role with something like:
然后,您可以使用以下命令检查用户角色:
if (in_array('myrole', $user->roles)) {
drupal_goto('page');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.