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