简体   繁体   中英

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? 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.

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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