If a user is logged in as admin, it works fine but if user is logged in, it is sending them their profile page. Why?. What files can I check?
$items['go/to/school'] = array(
'title' => 'Some page Title',
'page callback' => 'my_funct开发者_运维百科ion',
'access callback' => 'my_access',
'type' => MENU_CALLBACK
);
function my_function() {
echo "WHATS UP"; //NEVER SHOWS UP
}
Your callback function myaccess()
must return TRUE for that user, else that user has no access. This callback function can get arguments trough access arguments
. When you do not provide the access callback
it defaults to function user_access($access_string)
, in which case you still need to provide access arguments
, e.g. "access content".
Also note, that after each change in the hook_menu-code you must refresh the menu-cache, since this is cached quit heavily.
If you would like this page to be visible to all users (logged-in or anonymous), the simplest way is to just return TRUE in your access callback. For example:
'access callback' => TRUE,
Otherwise, like berkes said, your access callback must return TRUE for that user to see the page. For example:
function my_access() {
global $user;
return in_array('authenticated user', $user->roles);
}
This will return TRUE if the user has a role of "authenticated user" and FALSE if they do not.
精彩评论