Пример #1
0
 /**
  * Creates a new Tour model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tour();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 /**
  * Creates a new Tour model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tour();
     $concerts = Concert::findAll(['is_available' => 1]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'concerts' => $concerts]);
     }
 }
Пример #3
0
 /**
  * Creates a new Tour model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tour();
     $modelsOptionValue = [new CustomTourFields()];
     Model::loadMultiple($modelsOptionValue, Yii::$app->request->post());
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'modelsOptionValue' => empty($modelsOptionValue) ? [new CustomTourFields()] : $modelsOptionValue]);
     }
 }
Пример #4
0
 /**
  * Creates a new Tour model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tour();
     $tourtype = new Tourtype();
     $small = new FileUpload();
     $large = new FileUpload();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'tourtype' => $tourtype, 'small' => $small, 'large' => $large]);
     }
 }
Пример #5
0
 /**
  * Creates a new Tour model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tour();
     $booking = new Booking();
     $bookingFields = $booking->attributeLabels();
     unset($bookingFields['id']);
     unset($bookingFields['tour_id']);
     $data = Yii::$app->request->post();
     if ($model->load($data)) {
         if (isset($data['sort'])) {
             $model->sort = Json::encode($data['sort']);
         }
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'bookingFields' => $bookingFields]);
     }
 }
 /**
  * Creates a new Tour model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tour();
     $model->generateDefaultFields();
     $modelsCustomField = $model->customFields;
     if ($model->load(Yii::$app->request->post())) {
         $model->created_at = time();
         $modelsCustomField = Model::createMultiple(CustomField::classname());
         Model::loadMultiple($modelsCustomField, Yii::$app->request->post());
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsCustomField), ActiveForm::validate($model));
         }
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsCustomField) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     foreach ($modelsCustomField as $modelCustomField) {
                         $modelCustomField->tour_id = $model->id;
                         if (!($flag = $modelCustomField->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('create', ['model' => $model, 'modelsCustomField' => empty($modelsCustomField) ? [new CustomField()] : $modelsCustomField]);
 }