function page_example_arguments

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'
page_example_menu in page_example/page_example.module
Implements hook_menu().

File

page_example/page_example.module, line 189

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();
        // 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;
}