Example #1
0
 public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     if (!empty($this->id)) {
         $model = NewsFeed::findOne($this->id);
     }
     if (!isset($model) || empty($model)) {
         $model = new NewsFeed();
     }
     $model->setAttributes(['name' => $this->name, 'description' => $this->description, 'published' => $this->published, 'categories' => $this->categories, 'articles' => $this->articles]);
     if ($model->save(false)) {
         $this->id = $model->id;
     }
     return !empty($this->id);
 }
Example #2
0
 public function actionEditFeed($id)
 {
     $model = new NewsFeedForm();
     $feed = NewsFeed::findOne($id);
     if (!$feed) {
         throw new NotFoundHttpException("Не найдена лента с идентификатором {$id}");
     }
     $model->loadFeed($feed);
     if (!\Yii::$app->request->post("submited") && $model->load(\Yii::$app->request->post())) {
         if ($model->save()) {
             \Yii::$app->session->setFlash('saved', 'RSS лента успешно отредактирована!');
         } else {
             \Yii::$app->session->setFlash('error', 'Произошла ошибка при сохранении ленты!');
         }
     }
     return \Yii::$app->request->isAjax ? $this->renderAjax('edit', ['model' => $model]) : $this->renderPartial('edit', ['model' => $model]);
 }
 public function down()
 {
     \common\models\NewsFeed::deleteAll();
 }