示例#1
0
 /**
  * Updates an existing Tour 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);
     $modelsOptionValue = CustomTourFields::find()->where(['tourId' => $id])->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'modelsOptionValue' => empty($modelsOptionValue) ? [new CustomTourFields()] : $modelsOptionValue]);
     }
 }
示例#2
0
 public function getFields()
 {
     $positions = json_decode($this->positionFields);
     $this->additionFields = CustomTourFields::find()->where(['tourId' => $this->id])->all();
     $result = [];
     $index = 0;
     foreach ($positions as $key => $position) {
         if ($position !== 0) {
             $result[$position] = $this->{$position};
         } else {
             $result[$this->additionFields[$index]->name] = $this->additionFields[$index]->value;
             $index++;
         }
     }
     return $result;
 }