简体   繁体   English

如何在Drupal 7中为所有类型的用户设置子模块访问权限?

[英]How to Set sub module access permission for all type of user in drupal 7?

My user access permission check box is not working for admin, authenticated,anonymous user.I have created submodule and used hook_permission also it show check box on admin but not working on checked and unchecked.Please give me solution? 我的用户访问权限复选框不适用于管理员,已认证的匿名用户。我已经创建了子模块并使用了hook_permission,它也在admin上显示了复选框,但在选中和未选中状态不起作用。请给我解决方案吗? Thanks 谢谢

You probably got voted down because you have no code examples. 您可能因为没有代码示例而被否决。 It does make it difficult to answer your question, but it's pretty simple so I'll give it a shot. 确实很难回答您的问题,但是它非常简单,因此我将对其进行介绍。

If you are seeing the checkbox on the permissions page, then I know your hook_permission() is most likely properly declared. 如果您在权限页面上看到该复选框,那么我知道您的hook_permission()很可能已正确声明。

You did not mention how you are checking permission, so I will go through 2 methods: 您没有提到如何检查权限,因此我将介绍两种方法:

1) If you are using hook_menu(), look at the access_arguments line. 1)如果使用hook_menu(),请查看access_arguments行。 That is how you would set permissions for an entire page. 这样便可以设置整个页面的权限。

function mymodule_menu() {
  $items['abc/def'] = array(
    'page callback' => 'mymodule_abc_view',
    'access arguments' => array('administer my module')
  );
  return $items;
}

2) If you are wanting to check permission in a section of code, as a condition, you would use it this way. 2)如果您想在一段代码中检查权限,作为条件,则可以这种方式使用它。

if (user_access('administer my module')) {
  // show administrator stuff here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM