/** * Creates a new BaseNews model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new BaseNews(); if (Yii::$app->request->isPost) { $post = Yii::$app->request->post(); if (!($model->updateBaseTagsFromRequest($post) && $model->load($post) && $model->save(true, null, true))) { Yii::$app->session->setFlash('flash-warning', HLib::t('messages', 'There are errors in your form')); } else { return $this->redirect(Url::to(['/cms/web-news/index'])); } } // Affichage initial ou ré-affichage en cas d'erreur return $this->render('create', compact('model')); }
/** * @return \yii\db\ActiveQuery */ public function getBaseNews() { return $this->hasMany(BaseNews::className(), ['id' => 'base_news_id'])->viaTable('base_news_base_tag', ['base_tag_id' => 'id']); }
/** * @return \yii\db\ActiveQuery */ public function getBase() { return $this->hasOne(BaseNews::className(), ['id' => 'base_id']); }
/** * Updates an existing WebNews model. * If update is successful, the browser will be redirected to the 'view' page * * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $request = Yii::$app->request; $ok = true; $baseModel = null; if ($request->isPost) { // Mise à jour de la WebNews et de la BaseNews associée $post = $request->post(); /** @var BaseNews $baseModel */ if (!($baseModel = BaseNews::findOne($post['WebNews']['base_id']))) { $baseModel = new BaseNews(); } $ok &= $baseModel && $baseModel->updateBaseTagsFromRequest($post) && $baseModel->load($post) && $baseModel->save(true, null, true); $ok &= $model->load($post) && $model->save(); if (!$ok) { Yii::$app->session->setFlash('flash-warning', HLib::t('messages', 'There are errors in your form')); } else { Yii::$app->session->setFlash('flash-success', HLib::t('messages', 'Update successful')); if ($request->getBodyParam('action') == 'saveAndBackToList') { return $this->redirect(Url::to([$this->getControllerRoute() . '/index', 'page' => 1])); } } } // Affichage initial ou ré-affichage en cas d'erreur return $this->render('update', ['model' => $model, 'baseNews' => BaseNews::find()->orderBy('event_date DESC')->all(), 'languages' => Language::find()->orderBy('iso_639_code')->all(), 'baseModel' => $model->base]); }