hook_menu() 开头的通配符
hook_menu() wildcard at start
正在处理 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,
);
}
我搜索了 google,但我没有看到任何关于不能在 url 前面放置路径通配符的提及。
有人能注意到我在这里做错了什么吗?
还是drupal不支持通配符开头的路径。
非常感谢任何帮助,谢谢!
问题是您使用通配符作为第一个组件。如果您查看 hook_menu()
的 documentation,您将看到以下内容:
Wildcards in Paths Simple Wildcards
Wildcards within paths also work with integer substitution. For
example, your module could register path 'my-module/%/edit':
$items['my-module/%/edit'] = array(
'page callback' => 'mymodule_abc_edit',
'page arguments' => array(1),
);
When path 'my-module/foo/edit' is requested, integer 1 will be
replaced with 'foo' and passed to the callback function. Note that
wildcards may not be used as the first component.
正在处理 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,
);
}
我搜索了 google,但我没有看到任何关于不能在 url 前面放置路径通配符的提及。
有人能注意到我在这里做错了什么吗? 还是drupal不支持通配符开头的路径。
非常感谢任何帮助,谢谢!
问题是您使用通配符作为第一个组件。如果您查看 hook_menu()
的 documentation,您将看到以下内容:
Wildcards in Paths Simple Wildcards
Wildcards within paths also work with integer substitution. For example, your module could register path 'my-module/%/edit':
$items['my-module/%/edit'] = array( 'page callback' => 'mymodule_abc_edit', 'page arguments' => array(1), );
When path 'my-module/foo/edit' is requested, integer 1 will be replaced with 'foo' and passed to the callback function. Note that wildcards may not be used as the first component.