/**
  * Creates a new SelectedBlog model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new SelectedBlog();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #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;
     }
 }