'Page Example', 'page callback' => 'page_example_description', 'access callback' => TRUE, 'expanded' => TRUE, ); // This example checks if the user has permission to access the page. Users // that do not have the 'access simple page' permission will be denied. An // array containing the required permissions is given in 'access arguments' // and here we use the default 'access callback', which is 'user_access'. $items['examples/page_example/simple'] = array( 'title' => 'Simple - no arguments', 'page callback' => 'page_example_simple', 'access arguments' => array('access simple page'), ); // By using the MENU_CALLBACK type, we can register the callback for this // path but not have the item show up in the menu. // // Notice that the 'page arguments' is an array of numbers. These will be // replaced with the corresponding parts of the menu path. In this case a 0 // would be replaced by 'examples', a 1 by 'page_example', a 2 by 'arguments' // and likewise 3 and 4 will be replaced by whatever the user provides. We // will pass these last two as arguments to the page_example_arguments() // function. // // Only users with the 'access arguments page' permission have access. $items['examples/page_example/arguments/%/%'] = array( 'title' => 'Page example with arguments', 'page callback' => 'page_example_arguments', 'page arguments' => array(3, 4), 'access arguments' => array('access arguments page'), 'type' => MENU_CALLBACK, ); return $items; } function page_example_description() { return '

'.t('The page_example provides two pages, "simple" and "arguments". The simple page just returns a string for display. The arguments page takes two arguments and displays them, as in @arguments_link', array('@simple_link' => url('examples/page_example/simple', array('absolute' => TRUE)), '@arguments_link' => url('examples/page_example/arguments/23/56', array('absolute' => TRUE)))).'

'; } /** * A simple page callback. * * Page callbacks are required to return the entire page. The content * is then usually output via a call to theme('page'), where the theme system * will then surround the content in the appropriate blocks, navigation, and * styling. * * If you do not want to use the theme system (for example for outputting an * image or XML), you should print the content yourself and not return anything. */ function page_example_simple() { return '

' . t('Simple page: The quick brown fox jumps over the lazy dog.') . '

'; } /** * A more complex page callback that takes arguments. * * The arguments are passed in from the page URL. There in our hook_menu * implementation we instructed the menu system to extract the last two * parameters of the path and pass them to this function as arguments. */ function page_example_arguments($first, $second) { // Make sure you don't trust the URL to be safe! Always check for exploits. if (!is_numeric($first) || !is_numeric($second)) { // We will just show a standard "access denied" page in this case. drupal_access_denied(); return; // We actually don't get here. } $list[] = t("First number was @number.", array('@number' => $first)); $list[] = t("Second number was @number.", array('@number' => $second)); $list[] = t('The total was @number.', array('@number' => $first + $second)); return theme('item_list', $list); } /** * @} End of "defgroup page_example". */