public function actionIndex() { // Return all Diseases $response = array(); $response['PhotoPath'] = Yii::app()->params['siteDomain'] . Yii::app()->params['imagePath']; $response['Entries'] = array(); $response['Photos'] = array(); $response['PhotoLinker'] = array(); $tubers = Tuber::model()->findAll(); if ($tubers != null) { // Have something to return.. // Get images for each entry. foreach ($tubers as $tuber) { // Get all images for current tuber entry. $images = $tuber->images; if ($images != null) { foreach ($images as $image) { $response['PhotoLinker'][] = array('Id' => $image->Id, 'EntryId' => $image->TuberId, 'PhotoId' => $image->PhotoId); $response['Photos'][] = array("Id" => $image->photo->Id, "ImageName" => $image->photo->Name, "EntryId" => $tuber->Id); } } $response['Entries'][] = $tuber; } } $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 Tuber the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Tuber::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }