【问题标题】:drupal 6: redirect admin url for custom user roledrupal 6:为自定义用户角色重定向管理 url
【发布时间】:2011-04-14 07:34:28
【问题描述】:

我需要为用户角色重定向一个 url。

网址来自: http://www.example.com/admin

网址: http://www.example.com/admin/content/filter

用户角色: example-admin

因此,当用户(example-admin 角色)使用 url example.com/admin 登录管理面板时,他不会看到 Access Denied 页面,而是重定向到 content/filter 作为默认登录 url。

感谢帮助!非常感谢!

【问题讨论】:

    标签: drupal redirect drupal-6 admin user-roles


    【解决方案1】:

    您应该考虑使用规则模块 (http://drupal.org/project/rules)。规则模块允许您在登录时发出重定向到任意 URL。您还可以在发出重定向之前检查用户角色等条件。

    【讨论】:

      【解决方案2】:

      如果您想从自定义模块中的代码执行此操作,您可以实现 hook_menu_alter() 并调整访问回调函数以使用自定义覆盖:

      function yourModule_menu_alter(&$items) {
        // Override the access callback for the 'admin' page
        $items['admin']['access callback'] = 'yourModule_admin_access_override';
      }
      

      在该覆盖中,您执行标准访问检查并返回结果,但如果需要,请添加对特定角色的检查和重定向:

      function yourModule_admin_access_override() {
        global $user;
        // Does the user have access anyway?
        $has_access = user_access('access administration pages');
        // Special case: If the user has no access, but is member of a specific role,
        // redirect him instead of denying access:
        if (!$has_access && in_array('example-admin', $user->roles)) {
          drupal_goto('admin/content/filter');  // NOTE: Implicit exit() here.
        }
        return $has_access;
      }
      

      (注意:未经测试的代码,小心拼写错误)

      您将不得不触发菜单注册表的重建,以便获取菜单更改。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-05-26
        • 2011-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-09
        相关资源
        最近更新 更多