gpt4 book ai didi

php - 德鲁帕尔 7 : restrict access by path

转载 作者:行者123 更新时间:2023-12-04 00:03:31 24 4
gpt4 key购买 nike

我需要限制我网站的各个部分。我想通过限制对各种子路径的访问来做到这一点。路径访问模块实际上并不执行此操作。

您能否建议任何允许限制类似内容的机制:

成员(member)专区/编辑/*仅限于具有“编辑”角色的用户。

也许有一种方法可以用规则来做到这一点?我试过了,但找不到。

谢谢

最佳答案

为此您需要一个自定义模块,这并不难。这将是它的症结所在:

// Implements hook_init()
function mymodule_init() {
$restrictions = mymodule_get_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) {
if (in_array($role, $user->roles)) {
$valid = TRUE;
break;
}
}

if (!$valid) {
drupal_access_denied();
}
}
}
}

function mymodule_get_restrictions() {
// Obviously this data could come from anywhere (database, config file, etc.)
// This array will be keyed by path and contain an array of allowed roles for that path
return array(
'members-area/editors/*' => array('editor'),
'another-path/*' => array('editor', 'other_role'),
);
}

关于php - 德鲁帕尔 7 : restrict access by path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7711555/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com