0

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.

runeveryday
  • 2,751
  • 4
  • 30
  • 44

3 Answers3

4

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

30equals
  • 329
  • 1
  • 2
1

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?

Community
  • 1
  • 1
Ran Bar-Zik
  • 1,227
  • 9
  • 14
0

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.

Graham
  • 667
  • 3
  • 9