1 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 from 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'), a #theme is attached to the list so that it can be rendered as late as possible, giving to other parts of the system a chance to change it if necessary.
See backdrop_render() for further details.
Related topics
File
- modules/
examples/ page_example/ page_example.module, line 158 - Hook implementations for the 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.
backdrop_access_denied();
// We actually don't get here.
return;
}
$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(
// The theme function to apply to the #items.
'#theme' => 'item_list',
// The list itself.
'#items' => $list,
'#title' => t('Argument Information'),
);
return $render_array;
}