2009-10-02 32 views
3

是否有可能通过模块处理_menu()中的所有通配符。_menu()中的Drupal 6绝对通配符,有可能吗?

我知道具体的通配符像

display/page/% 但不会对路径display/page/3/andOrderBy/Name

工作,如果我要处理的参数不可预测ammount的像

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

我希望有一个display/* _menu()路径来处理所有自变量。

我该怎么办?

回答

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 ... 
} 
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); 
}; 
+2

顺便说一句,这是在Drupal标准的做法,前面加上你的模块名称的所有功能,以防止命名冲突,所以如果你的模块被称为“MYSEARCH”,你的回调应该命名为'mysearch_search'或'mysearch_FN_search' 。否则,向现有实例添加新模块可能会破坏网站。 – 2009-10-02 11:40:29

相关问题