drupal--hook_menu

2019-06-11 01:58发布

the info file is right,the following is my module file code. when i access the http://localhost/drupal/mymenu why it can't work.

  <?php
 function mymenu(){
    $item = array();
  $item['mymenu'] = array(
       'description'=>'test1',
      'page callback'=>'mymenu_test',
      'access arguments' => array('access mymenu'),
     'type'=>MENU_CALLBACK,
 );
 return $item;
 }

  function mymenu_perm(){
   return array('access mymenu');
  }

 function mymenu_test() {
 $output = 'hello world';
 return $output;
}

i have gave the 'access mymenu' permission to the anonymous.

4条回答
虎瘦雄心在
2楼-- · 2019-06-11 02:44

Try the following: use function name as modulename_menu and use 'access arguments' => array('access content').

<?php
  function test_menu(){
  $item = array();
  $item['mymenu'] = array(
  'description'=>'test1',
  'page callback'=>'mymenu_test',
  'access arguments' => array('access content'),
  'type'=>MENU_CALLBACK,
  );
  return $item;
  }

  function mymenu_test() {
  $output = 'hello world';
  return $output;
  }
查看更多
女痞
3楼-- · 2019-06-11 02:46

whenever you see a api function with hook_something, you have to replace the 'hook' part with the name of your module

in this case it's indeed mymenu_menu

查看更多
Juvenile、少年°
4楼-- · 2019-06-11 02:49

you need to flush menu cache(at least two times in drupal 7) after adding menu item with hook_menu.

查看更多
Emotional °昔
5楼-- · 2019-06-11 02:50

It should be

function mymenu_menu() { ... }

You don't need the $item = array(); there also.

查看更多
登录 后发表回答