What is the difference between MENU_NORMAL_ITEM and MENU_CALLBACK?
What is the difference between ME开发者_JAVA技巧NU_NORMAL_ITEM and MENU_CALLBACK?
The more precise answer is that hook_menu()
creates router items, and also menu links are generated. MENU_NORMAL_ITEM
generates a menu link which will appear in the navigation menu, while MENU_CALLBACK
does not add a menu link, so it won't appear in the menu.
MENU_NORMAL_ITEM
creates a menu item while MENU_CALLBACK
doesn't. That is the only difference.
Addition to the above comment, MENU_CALLBACK can be used in some scenarios such as AJAX. Example: example.com/ajax/country_list is a MENU_CALLBACK which returns a list of countries in HTML,JSON or XML format... This menu doesn't appear in the browser. You can visit http://api.drupal.org/api/group/menu/6 for more information.
Drupal maps urls to functions.
Means you need a function for every URL.The function is mostly present in a module.
ex mysite/add will have a mapping to a function in a module.
Many cases we don't want the URL as as a menu item but intend to use it for other purposes. The best example being a Ajax callback.
Ex: you have an auto-suggest form which calls a function suggest in the server.The front end Ajax will need a url to fire the request.Let the url be www.mysite/suggest
This is the case when you need a MENU_CALLBACK
function example_menu() {
$items['suggest'] = array(
'page callback' => 'example_suggest',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
function example_suggest() {
//you can return the autosuggested items to the page
}
精彩评论