/** * Return all Pests */ public function actionIndex() { $response = array(); $response['PhotoPath'] = Yii::app()->params['siteDomain'] . Yii::app()->params['imagePath']; $response['Entries'] = array(); $response['Photos'] = array(); $response['PhotoLinker'] = array(); $pestModels = Pest::model()->findAll(); if ($pestModels != null) { // Have something to return.. // Get images for each entry. foreach ($pestModels as $pestModel) { // Get all images for current pestModel entry. $images = $pestModel->images; if ($images != null) { foreach ($images as $image) { $response['PhotoLinker'][] = array('Id' => $image->Id, 'EntryId' => $image->PestId, 'PhotoId' => $image->PhotoId); $response['Photos'][] = array("Id" => $image->photo->Id, "ImageName" => $image->photo->Name, "EntryId" => $pestModel->Id); } } $response['Entries'][] = $pestModel; } } $this->sendResponse(200, CJSON::encode($response)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Pest the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Pest::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }