2014-12-01 1 views
0

CakePHP 웹 애플리케이션을 원격 안정 서버에 연결하는 특정 작업이 있습니다. 데이터 소스를 만들고 메서드 읽기는 훌륭하지만 데이터 저장 후 API는 처리 된 데이터 배열을 반환합니다.CakePHP 2.5 데이터 소스, 응답 생성 및 응답

데이터 배열을 반환하고 컨트롤러에서 사용하는 방법을 찾고 있습니다. 데이터 소스 파일에서

내 컨트롤러 코드

public function admin_generate() 
{ 
    $data = $this->request->data; 
    $data['path'] = 'special/generate'; 
    $this->Tool->create(); 
    if($this->Tool->save($data)){ 
     // handle response ???? 
    } 
    $this->set('data',$data); 
    $this->set('_serialize','data'); 

} 

public function create(Model $model, $fields = null, $values = null) 
    { 
    $data = array_combine($fields, $values); 
    $api = $this->config['api_path'].$data['path'].'?auth_key='.$this->config['auth_key']; 

    $json = $this->Http->post($api, $data); 

    $response = json_decode($json, true); 
    if (is_null($response)) { 
     $error = json_last_error(); 
     throw new CakeException($error); 
    } 
    return $response; // ?????? 
    } 

은 누군가가 나에게 컨트롤러에서 API 응답 데이터를 사용하는 올바른 방법을 게재 할 수 있습니까?

답변

1

게시물 질문 후 몇 분 후에 해결책을 찾았습니다. 여러분 중 한 분을 도울 수 있습니다.

소스 제어기

.... 

if (is_null($response)) { 
    $error = json_last_error(); 
    throw new CakeException($error); 
} 
// SOLUTION 
$model -> code = $response['code']; 
$model -> key = $response['key']; 
$model -> code_id = $response['code_id']; 
return true; 
..... 

..... 
if($this->Tool->save($data)){ 
     unset($data['path']); 
     $data['code'] = $this->Tool->code; 
     $data['key'] = $this->Tool->key; 
     $data['code_id'] = $this->Tool->code_id; 
    } 
.....