Drupal 6 _menu() 中的绝对通配符,可能吗?
-
19-09-2019 - |
题
是否可以通过模块处理 _menu() 中的所有通配符。
我知道特定的通配符,例如
display/page/%
但这不适用于路径 display/page/3/andOrderBy/Name
如果我想处理不可预测的参数量,例如
display/page/3/12/45_2/candy/yellow/bmw/turbo
我想要一个 display/*
_menu() 处理所有参数的路径。
我该怎么做 ?
解决方案
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 ...
}
其他提示
啊) 你是对
这里为i如何解决它。
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);
};
不隶属于 StackOverflow