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

标签 php drupal drupal-7

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

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

成员(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/

相关文章:

php - PDO异常 : SQLSTATE[HY000]: General error: 3 Error writing file '/tmp/MYHKgYpv' (Errcode: 28)

php - 在 webfarm 上运行 Drupal 应用程序(可扩展性),如何?

Drupal - 2 个单独的提要更新同一组节点(提要模块)

css - Drupal 正在向我的头脑中添加幻影样式表引用

php - 避免在循环期间连续显示空列

PHP:使用键 int 访问对象

jquery - 如何使用ajax提交drupal表单?

javascript - Drupal 7 将 jQuery 文件添加到所有页面

javascript - Chart.js 图表从未生成

PHP 将…替换为