处理一个hook_menu()函数,我使用以下代码工作正常:
function mymodule_menu(){
$items = array();
$items['assessment/%'] = array(
'page callback' => 'mymodule_assessment_page',
'page arguments' => 'array(1),
'access arguments' => array('access content'),
'file' => 'pages/mymodule.assessment.inc',
'type' => MENU_CALLBACK,
);
}
但是,当我尝试以下内容(清除缓存等后)时,我收到"找不到页面"错误。
function mymodule_menu(){
$items = array();
$items['%/assessment'] = array(
'page callback' => 'mymodule_assessment_page',
'page arguments' => 'array(0),
'access arguments' => array('access content'),
'file' => 'pages/mymodule.assessment.inc',
'type' => MENU_CALLBACK,
);
}
我搜索了谷歌,我没有看到没有提到无法在 url 的前面放置路径通配符。
谁能注意到我在这里做错了什么?还是drupal不支持以通配符开头的路径的情况。
任何帮助将不胜感激,谢谢!
问题是您使用通配符作为第一个组件。如果您查看hook_menu()
的文档,您将看到以下内容:
路径中的通配符简单通配符
路径中的通配符也适用于整数替换。为 例如,您的模块可以注册路径"my-module/%/edit":
$items['my-module/%/edit'] = array( 'page callback' => 'mymodule_abc_edit', 'page arguments' => array(1), );
当请求路径"my-module/foo/edit"时,整数 1 将是 替换为"foo"并传递给回调函数。请注意, 通配符不能用作第一个组件。