Ejemplo n.º 1
0
 /**
  * Updates an existing View 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);
     for ($i = 1; $i <= Lang::find()->count(); $i++) {
         $model_content[$i] = ViewLang::findOne(['id' => $id, 'lang_id' => $i]);
     }
     if (Model::loadMultiple($model_content, Yii::$app->request->post()) && Model::validateMultiple($model_content)) {
         foreach ($model_content as $key => $content) {
             $content->save(false);
         }
         return $this->redirect(['/view']);
     } else {
         return $this->render('update', ['model' => $model, 'model_content' => $model_content]);
     }
 }
Ejemplo n.º 2
0
 /**
  * @param null $lang_id
  * @return ViewLang|ActiveRecord
  */
 public function getContent($lang_id = null)
 {
     $lang_id = $lang_id === null ? Lang::getCurrent()->id : $lang_id;
     return $this->hasOne(ViewLang::className(), ['id' => 'id'])->where('lang_id = :lang_id', [':lang_id' => $lang_id]);
 }