我使用自定义模块将角色限制为drupal 7中的url,代码如下:
<?php
// Implements hook_init()
function restrict_access_init() {
$restrictions = restrict_access_restrictions();
global $user;
foreach ($restrictions as $path => $roles) {
// See if the current path matches any of the patterns provided.
if (drupal_match_path($_GET['q'], $path)) {
// It matches, check the current user has any of the required roles
$valid = FALSE;
foreach ($roles as $role) {
print implode("','",$user ->roles);
if (in_array($role, $user->roles)) {
$valid = TRUE;
break;
}
}
if (!$valid) {
drupal_access_denied();
}
}
}
}
function restrict_access_restrictions() {
// This array will be keyed by path and contain an array of allowed roles for that path
return array(
'path/path' => array('admin'),
);
}
?>
这确实限制了访问权限,但它会在页脚后呈现未设置样式的页面。
为什么会发生这种情况的任何想法? 我现在处于迷失状态。
答案 0 :(得分:0)
我需要添加module_invoke_all('exit');出口();在drupal_acess_denied()下;
e.g。
drupal_acess_denied();
module_invoke_all('exit');
exit();