开发者

Drupal - how to register a MENU_CALLBACK that is accessable to all users(even anonymous ones)?

I'm trying to learn Drupal 6. I want to register the path '/topic' to a MENU_CALLBACK using hook_menu(). Here's what I have:

function mymodule_menu() {
   $items = array()
   $items['foo'] = array( 
       'page callback' => 'show_page_foo',
       'access callback'   => 'user_access',
       'access arguments' => array('access foo content'),
       'type'     => MENU_CALLBACK 
     );
}
function show_page_foo() {
   //show foo page
}

This works fine for a logged in user. But when I visit the path as an anonymous user it shows 'Access Denied' message. What must be the 'access callback' and 'access arguments' values to have this accessible to all visitors?

I remember I made this work by simply saying 'access' => TRUE in开发者_StackOverflow Drupal 5. No longer works in Drupal 6.


You can use permission like you show and give the permission to anonymous users.

You can also do

'access callback' => TRUE


'access callback' should be a function returning a boolean value, and 'access callback' => TRUE will work fine. Anyway i would suggest you not to use a constant value, for a cleaner access control. Use

'access callback' => 'user_access',
'access arguments' => array('access content'),

instead, that's one generic enough permission. Or try the permission better fitting your needs. You can omit the access callback itself, since user_access is used as the default one.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜