2017-09-13 1 views
4

jQuery를 사용하여 AJAX 쿼리를 실행하고 싶지만 응답이 원하는 것이 아닙니다.Yii2 및 Ajax : 응답이 SQL 쿼리 결과가 아닙니다.

클라이언트 측 :

$.ajax({ 
    url: "/family?idperson=1234", 
    dataType: 'json', 
    success: function(res) { 
     console.log(JSON.stringify(res, null, 4)); 
    }, 
    error: function(err) {     
    } 
}); 

서버 측 :

public function actionFamily($idperson) 
{ 
    $searchModelFamily = new FamilySearch(); 
    $dataProvider = $searchModelFamily->searchByIdperson(Yii::$app->request->queryParams, $idperson); // This database query works great. 

    Yii::$app->response->format = Response::FORMAT_JSON; 
    return $dataProvider; 
} 

이는 JSON 객체의 컨텐츠입니다 : 그것은 SQL 쿼리의 일부에 보인다. 하지만 SQL 결과이 필요합니다.

{ 
    "query": { 
     "sql": null, 
     "on": null, 
     "joinWith": null, 
     "select": null, 
     "selectOption": null, 
     "distinct": null, 
     "from": null, 
     "groupBy": null, 
     "join": null, 
     "having": null, 
     "union": null, 
     "params": [], 
     "where": { 
      "idperson": "1234" 
     }, 
     "limit": null, 
     "offset": null, 
     "orderBy": null, 
     "indexBy": null, 
     "emulateExecution": false, 
     "modelClass": "app\\models\\Family", 
     "with": null, 
     "asArray": null, 
     "multiple": null, 
     "primaryModel": null, 
     "link": null, 
     "via": null, 
     "inverseOf": null 
    }, 
    "key": null, 
    "db": null, 
    "id": null 
} 
+0

현재 결과는 무엇이며 원하는 결과는 무엇입니까? –

답변

4

actionFamily가 가져 오는 데이터가 아닌 DataProvider 객체를 반환하는 것처럼 보입니다. actionFamily가 yii \ rest \ 컨트롤러 내의 메소드라면 작동해야하지만, 내 추측으로는 정상적인 yii \ web \ 컨트롤러를 사용하고있는 그대로 객체를 반환합니다.

DataProvider에의 데이터를 얻기 위해 시도 ...이에

return $dataProvider; 

...

return $dataProvider->getModels(); 

을이을 변경하거나 (그것이 REST 기능의 경우) 컨트롤러 클래스를 변경 위에 논의 된 바와 같이.