Drupal 7 example module, page not found, why?

后端 未结 3 611
甜味超标
甜味超标 2021-01-26 18:09

I wrote a simple test module example, 2 files, test.module, test.info, and enabled them in drupal 7 modules.

I cleared all the cache, and still when i\'m trying to go to

相关标签:
3条回答
  • 2021-01-26 18:38

    Uninstall and reinstall your custom module. I hope this will help you. Because it's necessary for drupal core to know the newly created path created using hook_menu.

    0 讨论(0)
  • 2021-01-26 18:43

    You have posted almost the same question once and twice before. Why don't you update the original one instead of posting new ones?

    • The hook_menu() does not have the $may_cache argument in Drupal 7. You should remove it. However, it should not solve your problem as it is unset and false. Thus, the $items should still be populated.

    • It is correct, as jprofitt says, that you should change 'callback' to 'page callback'.

    • There is no such thing as 'access', but there is 'access callback' and 'access arguments'. You are most likely looking for 'access callback'. However, you can't just set it to 'true'. It expects a function name which returns either 'true' or 'false'. It defaults to 'user_access', so you should just leave it that way. However, you might want to set 'access arguments' to something like 'access content'.

    Does the following piece of code work better?

    function test_world_menu() {
    
      $items = array();
    
      $items['hello'] = array(
        'title' => 'Hello World!', 
        'page callback' => 'test_world_page', 
        'access arguments' => array('access content'), 
        'type' => MENU_CALLBACK 
        );
    
      return $items;
    }
    

    It seems that you haven't really had a look at the documentation. I might be wrong. However, the documentation at api.drupal.org is always a good start to look when you want to learn the basics of how something work.

    0 讨论(0)
  • 2021-01-26 18:57

    You should probably change 'callback' to 'page callback', as I don't believe hook_menu() has just a plain "callback" option. And since you're working with Drupal 7, its hook_menu() actually doesn't have parameters.

    0 讨论(0)
提交回复
热议问题