/** * Creates a new Event model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Event(); 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 actionCreateevent() { $request = \yii::$app->request; $bookingModel = new Booking(); $eventModel = new Event(); $eventEntryModel = new EventEntry(); $validate = false; $bookingModel->load($request->post()); if (yii::$app->CalendarComponent->canCreateEvents($bookingModel->calendar_id)) { $validate = true; } else { $bookingModel->addError('event_id', 'Cannot use this calendar. Double check the read only setting - '); } if ($validate && $bookingModel->validate()) { $eventModel->load(['Event' => $bookingModel->attributes]); if ($eventModel->validate()) { try { $transaction = \yii::$app->db->beginTransaction(); $eventModel->save(false); $eventEntryModel->load(['EventEntry' => $bookingModel->attributes]); $eventEntryModel->event_id = $eventModel->primaryKey; if ($eventEntryModel->validate()) { $eventEntryModel->save(false); yii::$app->AjaxResponse->error = false; } else { yii::$app->AjaxResponse->message = array_values($eventEntryModel->getErrors()); } $transaction->commit(); yii::$app->AjaxResponse->message = $bookingModel->jsObject; } catch (Exception $e) { $transaction->rollBack(); } } else { yii::$app->AjaxResponse->message = array_values($eventModel->getErrors()); } } else { yii::$app->AjaxResponse->message = array_values($bookingModel->getErrors()); } yii::$app->AjaxResponse->sendContent(); }