Drupal 7 drupal 7钩子菜单不工作

Drupal 7 drupal 7钩子菜单不工作,drupal-7,hook,Drupal 7,Hook,我们已经了解到,要在drupal中使用/截取URL,模块可以使用钩子菜单进行相关处理 在看过Drupal的教程后,我尝试根据需要实现它。然而,它似乎根本不起作用。当输入url时,它只返回找不到页面的错误 模块的信息文件如下所示: name = news service description = Module for news rest service dependencies[] = services files[] = news.module core = 7.x <?php

我们已经了解到,要在drupal中使用/截取URL,模块可以使用钩子菜单进行相关处理

在看过Drupal的教程后,我尝试根据需要实现它。然而,它似乎根本不起作用。当输入url时,它只返回找不到页面的错误

模块的信息文件如下所示:

name = news service
description  = Module for news rest service
dependencies[] = services
files[] = news.module
core = 7.x
<?php

 function news_service_menu()
 {
     $items['/get/news'] = array(
        'page callback' => 'get_latest_news'
     );
     return $items;
 }

 function get_latest_news($page)
 {
     return "requested page is $page";
 }
/* drupal recommends not to add the ending php tag*/ 
.module文件如下所示:

name = news service
description  = Module for news rest service
dependencies[] = services
files[] = news.module
core = 7.x
<?php

 function news_service_menu()
 {
     $items['/get/news'] = array(
        'page callback' => 'get_latest_news'
     );
     return $items;
 }

 function get_latest_news($page)
 {
     return "requested page is $page";
 }
/* drupal recommends not to add the ending php tag*/ 

注册路径时不应添加前导斜杠。将
$items['/get/news']
更改为
$items['get/news']

您可能还需要指定访问参数并为某些角色设置权限,例如

'access arguments'=>数组('access custom page'),

或者使用自己的访问回调函数

请在此处阅读有关hook_菜单和访问参数的更多信息:


当否决某个问题或答案时,请陈述你的理由,以便其他人从中受益

注册路径时不应添加前导斜杠。将
$items['/get/news']
更改为
$items['get/news']

您可能还需要指定访问参数并为某些角色设置权限,例如

'access arguments'=>数组('access custom page'),

或者使用自己的访问回调函数

请在此处阅读有关hook_菜单和访问参数的更多信息:


当否决某个问题或答案时,请陈述你的理由,以便其他人从中受益

我不知道为什么这被否决了。对我来说似乎是个很好的答案。我不知道为什么这被否决了。对我来说似乎是个好答案。