| 6 page_example.module | page_example_arguments($first, $second) |
| 7 page_example.module | page_example_arguments($first, $second) |
| 8 page_example.module | page_example_arguments($first, $second) |
A more complex page callback that takes arguments.
This callback is mapped to the path 'examples/page_example/arguments/%/%'.
The % arguments are passed in from the page URL. 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.
This function also demonstrates a more complex render array in the returned values. Instead of just rendering the HTML with a theme('item_list'), the list is left unrendered, and a #theme attached to it so that it can be rendered as late as possible, giving more parts of the system a chance to change it if necessary.
Consult Render Arrays documentation for details.
Related topics
1 string reference to 'page_example_arguments'
File
- page_example/
page_example.module, line 182 - Module file for page_example_module.
Code
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));
$render_array['page_example_arguments'] = array(
'#theme' => 'item_list', // The theme function to apply to the #items
'#items' => $list, // The list itself.
'#title' => t('Argument Information'),
);
return $render_array;
}
Login or register to post comments