3

is it possible to handle all wildcards in _menu() by module.

I know about specific wildcards like

display/page/% but that won't work for paths display/page/3/andOrderBy/Name

what If I want to handle unpredicted ammount of parameters like

display/page/3/12/45_2/candy/yellow/bmw/turbo

I want to have one display/* _menu() path to handle all ARGUMENTS.

how can I do it ?

apaderno
  • 28,547
  • 16
  • 75
  • 90
David King
  • 2,010
  • 5
  • 19
  • 23

2 Answers2

3

Drupal will pass any additional URL elements as additional parameters to your hook_menu callback function - use func_get_args() in your callback to get them.

So if you register only one wildcard display/page/%, but the actual request has two additional elements display/page/3/andOrderBy/Name, your callback will be passed '3' as an explicit parameter, but also 'andOrderBy' and 'Name' as implicit additional ones.

Example callback:

function yourModuleName_display_callback($page_number) {
  // Grab additional arguments
  $additional_args = func_get_args();
  // Remove first one, as we already got it explicitely as $page_number
  array_shift($additional_args);
  // Check for additional args
  if (!empty($additional_args)) {
    // Do something with the other arguments ...
  }
  // other stuff ...
}
Henrik Opel
  • 19,341
  • 1
  • 48
  • 64
0

ah ;) you were right

here is how i solved it.

function mysearch_menu() {
$items['mysearch/%'] = array(
'page callback' => 'FN_search',
'access callback' => TRUE,
);
return $items;
}


function FN_search()
{
    return print_r(func_get_args(),true);
};
David King
  • 2,010
  • 5
  • 19
  • 23
  • 2
    BTW, it is standard practice in Drupal to prefix all your functions with your modules name to prevent naming conflicts, so if your module is called 'mysearch', your callback should be named `mysearch_search` or `mysearch_FN_search`. Otherwise adding a new module to an existing instance might break the site. – Henrik Opel Oct 02 '09 at 11:40