已经读过在drupal中使用/截取URL,模块可以使用钩子菜单进行相关处理。
在看过Drupal上的教程后,尝试根据需要实现它。但它似乎根本没有工作。输入网址时,只会返回无法找到网页的错误。
模块的info文件如下:
name = news service
description = Module for news rest service
dependencies[] = services
files[] = news.module
core = 7.x
<。> .module文件如下:
<?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*/
drupal安装在localhost / drupal上。我正在尝试的网址是:localhost / drupal / get / news / 1
总结要求,我试图制作一个简单地将自定义内容类型(新闻文章)作为JSON返回的REST服务。
任何帮助将不胜感激。
答案 0 :(得分:3)
注册路径时不应添加前导斜杠。将$items['/get/news']
更改为$items['get/news']
您可能还需要指定访问参数并为某些角色设置权限,例如
'access arguments' => array('access custom pages'),
或使用您自己的访问回调函数。
在此处阅读有关hook_menu和访问参数的更多信息:https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_menu/7
当对问题或答案进行投票时,请说明您的理由,以便其他人从中受益。