다음 노드와 사용자 정의 모듈을 생성하고 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;
*/
}
도움을 주셔서 감사합니다. 새로운 **보기 **를 만들 수있는 방법이 있습니까 ** 모든 노드 다음에 노드 당 모든 주석 **이 표시됩니다. 나중에 아이폰 앱에서 필요한 노드로 필터링 할 것입니다. 현재 뷰를 사용하여 노드 당 최신 코멘트 만 표시 할 수 있습니다. – Shuaib
주석보기를 만든 다음 소유하고있는보기에 관계를 추가 할 수 있습니다. 그런 다음보기 스타일을 표로 설정하고 소유 노드를 "그룹화"하십시오. 게시일까지 댓글을 정렬해야합니다. –
당신이 말했듯이 나는보기를 사용하여 그것을하고 싶습니다. 그러나 부모보기가 해당 노드 만로드하고 자식보기는 주석을 표시 할 수 있도록 iphone 응용 프로그램에서 노드 ID를 보내야합니다. 노드 ID를 지정하는 방법이 있습니까? – Shuaib