drupal why MENU_NORMAL_ITEM can't work
i haved written a simple module to practice the hook_menu. but it doesn't work. what's wrong with my code.
function mymenu1_menu(){
$item = array();
$item['mymenu/menu'] = array (
开发者_高级运维 'description' =>'test1',
'page callback' => 'mymenu_test_access',
'access callback' => 'mymenu_is_test_access',
'type' =>MENU_NORMAL_ITEM,
);
return $item;
}
function mymenu_test_access(){
$output = 'you're logged';
return $output;
}
function mymenu_is_test_access(){
return $GLOBALS['user']->uid >0 ;
}
my module name is mymenu1, the module info file is right, the cache is cleared. but in the navigation part, i can't see the menu that i created. thank you.
for starters - there's an error in your code
function mymenu_test_access(){
$output = 'you're logged';
return $output;
}
you need to escape the single quote in your $output. $output = 'you're logged';
should be
$output = 'you\'re logged';
try fixing that and see how it goes
There is Probably a problem with the access control. I really don't sure what did you tried to do in function mymenu_is_test_access, but it doesn't return the proper values (and full of typos).
Try using:
'access arguments' => array('access content'),
for creating menu item for every user (even anonymous users) .
If you want to restrict access to specific group/role - read this one: Can someone explain "access arguments" in Drupal?
Does your system have an entry for "mymenu"? Because if it doesn't exist, then the path "mymenu/menu" will not be valid. At least, that's how I understand it.
精彩评论