简体   繁体   中英

Drupal: why can't user admin access my module pages?

I am working on a drupal 6.x module which consists of several page as defined in the .module page. The problem is that when I visit those pages as admin, I get access denied. I thought that admin (user 1) could access anything? Here the code for some of the pages:

function foobar_menu()
{
 $items['admin/foobar'] = array(
   'title' => 'administer foobar',
   'page callback' => 'foobarpage',
 );

 $items['admin/foobar/baz'] = array(
   'title' => 'Do baz',
   'page callback' => 'drupal_get_form',
   'page arguments' =>array('foobarpage'),
 );

So how do I make sure that only admin can see these pages and the rest get a "page does not exists" error?

EDIT: I found solution here .

You need to define access arguments for every single menu item.

See drupal.org documentation on this subject.

For example you hook_menu may look something like this:

$items['admin/foobar'] = array(
    'title' => 'administer foobar',
    'page callback' => 'foobarpage',
    'access arguments' => array('administer site configuration'),
);

wiifm's answer is correct, but the other alternative (if you don't want to use 'administer site configuration') is to create a custom access callback function that checks either uid == 1 or create a custom priv.

I don't know what is best for your case, but chances are you want to do as wiifm suggests.

When you say admin, you mean the first user you created oa specific user that you gave all privileges. In anyway, as wiifm said above, even for admin, you must add the 'access argument' entry in your menu items, once you do that, and if you do what wiifm says, you should be able to access the menu item with admin and not with any other user (unless you give that permission to other users, which is unlikely).

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