Ejemplo n.º 1
0
 /**
  * Finds the BaseTag model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return BaseTag the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = BaseTag::findOne($id)) !== null) {
         return $model;
     }
     throw new NotFoundHttpException('Modèle introuvable : #' . $id);
 }
Ejemplo n.º 2
0
 /**
  * Updates an existing WebTag model.
  *
  * @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 du WebTag et du BaseTag associé
         /** @var BaseTag $baseModel */
         if (!($baseModel = BaseTag::findOne($request->post()['WebTag']['base_id']))) {
             $baseModel = new BaseTag();
         }
         $ok &= $baseModel && $baseModel->load($request->post()) && $baseModel->save();
         $ok &= $model->load($request->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]));
             }
         }
     } else {
         $baseModel = $model->base;
     }
     // Affichage initial ou ré-affichage en cas d'erreur
     $baseTags = BaseTag::find()->orderBy('code')->all();
     $languages = Language::find()->orderBy('iso_639_code')->all();
     return $this->render('update', compact('model', 'baseTags', 'languages', 'baseModel'));
 }