示例#1
0
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id)
 {
     try {
         $model = $this->loadModel($id);
         $content = $model->content;
         $pattern = '/[{]G[0-9]{3,6}[}]/';
         preg_match_all($pattern, $content, $matches);
         if (!empty($matches)) {
             for ($i = 0; $i < count($matches[0]); $i++) {
                 if (!empty($matches[0][$i])) {
                     $code = $matches[0][$i];
                     $gallery_id = Galleries::model()->find(array('condition' => 'code = "' . $code . '"'))->id;
                     if (!empty($gallery_id)) {
                         $photos = Photos::model()->findAll(array('condition' => 'gallery_id =' . $gallery_id));
                         $htmlReplace = ActiveRecord::getHtmlGalleryBox($photos);
                     }
                 }
                 $content = str_replace($code, $htmlReplace, $content);
             }
         }
         $this->render('view', array('model' => $model, 'content' => $content, 'actions' => $this->listActionsCanAccess));
     } catch (Exception $e) {
         Yii::log("Exception " . print_r($e, true), 'error');
         throw new CHttpException("Exception " . print_r($e, true));
     }
 }