Drupal - how to register a MENU_CALLBACK available to all users (even anonymous)?

I'm trying to learn Drupal 6. I want to register the '/ topic' path to MENU_CALLBACK with 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 great for a logged in user. But when I visit the path as an anonymous user it shows "Access Denied" message. What should be the "access callback" and "argument access" values ​​so that this is available to all visitors?

I remember I made this work just by saying 'access' => TRUE

in Drupal 5. No longer works in Drupal 6.

+2


a source to share


2 answers


You can use the permission you are showing and grant permission to anonymous users.

You can also do



'access callback' => TRUE

      

+5


a source


'access callback'

there should be a function that returns a boolean and 'access callback' => TRUE

will work fine. Anyway, I suggest you don't use a constant value for cleaner access control. Use

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

      



instead, one generic resolution is sufficient. Or try the resolution that best suits your needs. You can omit the access callback itself as it is user_access

used as a standard one.

+1


a source







All Articles