如果没有直接的方法可以通过服务模块获取它,那么有一种方法可以通过创建您自己的自定义模块并实现 hook_services_resources 来获取节点及其注释。这种钩子机制类似于 drupal 菜单钩子。
这是用 drupal 7 编写的代码片段,但它也应该在 drupal 6 中工作。
Url : <drupal site>/<REST server endpoint>/my_rest_api/<node id>.json
让我看看它是否有效,否则我将在 D6 中创建整个模块并将其粘贴到此处。
/**
* Implements hook_services_resources().
* my_rest_api should appear in your resource list and do enable it before using it.
*/
function YOURMODULE_services_resources() {
return array(
'my_rest_api' => array(
'retrieve' => array(
'callback' => 'getMyRestNodeWithComments',
'args' => array(
array(
'name' => 'nid',
'optional' => FALSE,
'source' => array('path' => 0),
'type' => 'int',
),
),
'access callback' => 'getMyRestAcces',
),
),
);
}
/**
* Get the node along with comment
*/
function getMyRestNodeWithComments($nid) {
$node = node_load($nid);
$node->comments = getMyRestCommentByNid($nid);
return $node;
}
/**
* Access callback.
* TRUE for now but you change it according to your requirement
*/
function getMyRestAcces() {
return TRUE;
}
/**
* Get comment by nid
*/
function getMyRestCommentByNid($nid){
//drupal 7
$query = db_select('comment', 'c');
$comments = $query
->fields('c')
->condition('c.nid', $nid)
->execute()
->fetchAll();
return $comments;
/*
//In Drupal 6 something like this
$result = db_query("select * from {comment} where nid = %d",$nid);
$records = array();
while($row = db_fetch_array($result)){
array_push($records, $row);
}
return $records;
*/
}