开发者

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

开发者 https://www.devze.com 2023-02-01 06:47 出处:网络
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 (use

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' => '开发者_C百科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 o a 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消