/**
  * Finds the Source model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Source the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Source::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #2
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         // source
         if (isset($this->source_id) && $this->source_id > 0) {
             $source = Source::findOne($this->source_id);
             if (isset($source)) {
                 $this->source_title = $source->name;
                 $this->source_url = $source->url;
             }
         }
         // slug
         $this->slug = $this->genSlug($this->title);
         // created_at
         $this->created_at = date('Y-m-d H:i:s', strtotime($this->created_at));
         // content
         //            $pattern = '~<a .*href=".*" .*>(.*)</a>~U';
         //            $this->content = preg_replace($pattern, '$1', $this->content);
         // Selected blogs
         if (isset($this->selected_blog)) {
             if ($this->selected_blog) {
                 $selectedBlog = SelectedBlog::find()->where(['post_id' => $this->id])->one();
                 if (!isset($selectedBlog)) {
                     $selectedBlog = new SelectedBlog();
                     $selectedBlog->post_id = $this->id;
                     $selectedBlog->save(false);
                 }
             } else {
                 SelectedBlog::deleteAll(['post_id' => $this->id]);
             }
         }
         return true;
     } else {
         return false;
     }
 }