欢迎各位兄弟 发布技术文章
这里的技术是共享的
function custome_thirtieth_menu(&$items)
{
$items['get_keyword_file_info'] = array(
'title' => '得到macos上关键字文件信息',
'page callback' => 'custome_thirtieth_get_keyword_file_info',
'access arguments' => array('access content'),
);
return $items;
}
drupal 7 Warning: Missing argument 1 for custome_thirtieth_menu() 在 custome_thirtieth_menu() (行 2 在 /www/web/aaaaa_bbbbb-ict_com/public_html/sites/all/modules/custom/custome_thirtieth/custome_thirtieth.module).
您的代码问题是因为 Drupal 7 的 hook_menu()
函数定义错误导致的。在 Drupal 7 中,hook_menu()
不需要手动传入参数,系统的菜单系统会自动处理调用。
您的代码中:
phpfunction custome_thirtieth_menu(&$items) { ... }
错误:&$items
参数是手动传入引用,但 Drupal 7 不会这样调用 hook_menu()
,所以会报错 Missing argument 1 for custome_thirtieth_menu()
。
hook_menu()
应该写成:
phpfunction custome_thirtieth_menu() { $items = array(); // 初始化数组 $items['get_keyword_file_info'] = array( 'title' => '得到 macOS 上关键字文件信息', 'page callback' => 'custome_thirtieth_get_keyword_file_info', 'access arguments' => array('access content'), // 访问权限 ); return $items; // 返回菜单项 }
移除 &$items
:hook_menu()
不需要手动传入参数,系统会自动调用的。
初始化 $items
:函数内部先定义 $items = array();
,然后填充菜单项。
返回 $items
:确保 return $items;
,Drupal 会读取这个返回值注册菜单。
page callback
函数存在?
你定义的 custome_thirtieth_get_keyword_file_info
必须存在,否则访问页面时会报 404。
示例实现:
phpfunction custome_thirtieth_get_keyword_file_info() { return "这是 macOS 关键字文件信息页面"; }
访问权限 access arguments
'access content'
是 Drupal 默认权限,表示“能查看内容的用户”可访问。
如果需要更高权限,可以改成 'administer site configuration'
等。
修改后,缓存(drush cc all
或 admin/config/development/performance
清除缓存)再测试,应该就不会报错了。