Search code examples
drupaldrupal-6drupal-routes

Multiple arguments on menu callback


I know how to pass one argument to a menu callback

  $items['someaddress/%'] = array(
    'title' => 'title',
    'page callback' => 'some_function',
    'page arguments' => 1,
    'type' => MENU_CALLBACK
  );

I don't understand why the argument being passed is $_POST['nid'] but this works. It corresponds to page argument 1.

function some_function (){

    $node = isset($_POST['nid']) ? node_load($_POST['nid']) : FALSE;

}

I'm now trying to pass multiple arguments. $items['someaddress/%/%/%'] = array( and is looking for a code sample of how I do that.

Thanks!


Solution

  • Use an array for page arguments:

    $items['someaddress/%/%/%'] = array(
      'title' => 'title',
      'page callback' => 'some_function',
      'page arguments' => array(1, 2, 3),
      'type' => MENU_CALLBACK,
    );
    
    function some_function($arg1, $arg2, $arg3) {
      // Insert code here
    }
    

    You should always keep arguments passed to menu callbacks as an array, anyway.

    FYI: the behavior you are seeing is how Drupal's menu system is designed. The number corresponds to each argument being passed to the menu. 1 is the first argument, 2 is the second, etc.