2012-10-03 2 views
2

동작 실행 중 REST 동작을 수행하는 방법이 있습니까? 그래서 최종 결과는Restler : 내부 동작

[{ 
    "id" : 1, 
    "title" : "This is a book.", 
    "owner_id" : 4 
}] 

하지만 내가하고 싶은 것은 상기 목적을 반환하기 전에이다하는 GET /index.php/user/4를 수행하십시오 : 나는 GET /index.php/book/1을 수행하는 경우 예를 들어, 나는이 다음 수신 할 수 있습니다

[{ 
    "id" : 1, 
    "title" : "This is a book.", 
    "owner" : { 
     "id" : 4, 
     "name" : "John Smith", 
     "age" : 40 
    } 
}] 

답변

1

내부적으로 다른 API 메소드를 호출하여 Restler와 함께이 일을 직접하는 대신 서버

class User{ 
    public function get($id, $includeOwner = true){ 
     $result = getUserFromDB($id) 
     if($includeOwner){ 
      $result['owner'] = $this->get(getOwnerIdFromDB($id),false); 
     } 
    } 
    return $result; 
} 

하나의 호출을 낭비하고 심지어 간단한 방법이있다 HTH

관련 문제