/** * Creates a new TourFields model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new TourFields(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionCreate($id) { $request = Yii::$app->request; if ($id != null) { $tour = Tour::findOne($id); if ($tour != null) { $tour_field = new TourFields(); $tour_field->load(Yii::$app->request->post()); $last_field = $tour->getFields()->orderBy(['sort' => SORT_DESC])->one(); $tour_field->sort = $last_field['sort'] + 1.0; $tour_field->type = 1; $tour_field->link('tour', $tour); if ($tour_field->validate()) { $tour_field->save(); Yii::$app->getSession()->setFlash('message', Yii::t('app', 'Successfully created new custom field ' . $tour_field->name)); } } } return $this->redirect(Yii::$app->request->referrer); }