drupal 6:重定向自定义用户角色的管理 URL

发布于 2024-09-24 12:16:19 字数 481 浏览 2 评论 0原文

我需要重定向用户角色的 url。

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

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

用户角色: example-admin

因此,当用户(example-admin 角色)使用 URL example.com/admin 登录管理面板时,他将不会看到“拒绝访问”页面,但重定向到 content/filter 作为默认登录 URL。

赞赏有帮助!多谢!

I need to redirect a url for a user role.

URL From: http://www.example.com/admin

URL TO: http://www.example.com/admin/content/filter

User Role: example-admin

So, when a user (example-admin role) login to admin panel with the url example.com/admin , he will not see Access Denied page, but redirected to content/filter as default login url.

Appreciate helps! Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一身仙ぐ女味 2024-10-01 12:16:19

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

You should consider using the Rules module ( http://drupal.org/project/rules ). Rules module allows you to issue redirects on login to an arbitrary URL. You can also check for conditions like the role of the User before issuing the redirect.

2024-10-01 12:16:19

如果您想从自定义模块中的代码执行此操作,可以实现 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;
}

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

您将必须触发菜单注册表的重建才能拾取菜单更改。

If you want to do it from code in a custom module, you could implement hook_menu_alter() and adjust the access callback function to use a custom override:

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

In that override, you perform the standard access check and return the result, but add the check for the specific role and redirect instead, if needed:

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;
}

(NOTE: Untested code, beware of typos)

You will have to trigger a rebuild of the menu registry for the menu alteration to be picked up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文