3

是否可以按模块处理 _menu() 中的所有通配符。

我知道特定的通配符,例如

display/page/% 但这不适用于路径display/page/3/andOrderBy/Name

如果我想处理无法预测的参数数量,例如

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

我想要一个display/*_menu() 路径来处理所有参数。

我该怎么做 ?

4

2 回答 2

3

Drupal 会将任何附加的 URL 元素作为附加参数传递给您的hook_menu回调函数 - 在您的回调中使用func_get_args()来获取它们。

因此,如果您只注册一个通配符display/page/%,但实际请求有两个附加元素display/page/3/andOrderBy/Name,则您的回调将作为显式参数传递 '3',但也会将 'andOrderBy' 和 'Name' 作为隐式附加参数传递。

回调示例:

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 ...
}
于 2009-10-02T10:41:18.463 回答
0

啊 ;) 你是对的

这就是我解决它的方法。

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);
};
于 2009-10-02T11:29:55.623 回答