/**
  * Creates a new Reservation model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Reservation();
     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
 public function actionGrid()
 {
     $query = Reservation::find();
     $searchModel = new Reservation();
     if (isset($_GET['Reservation'])) {
         $searchModel->load(Yii::$app->request->get());
         $query->andFilterWhere(['customer_id' => isset($_GET['Reservation']['customer_id']) ? $_GET['Reservation']['customer_id'] : null]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     return $this->render('grid', compact('dataProvider'));
 }
 public function actionDetailDependentDropdown()
 {
     $showDetail = false;
     $model = new Reservation();
     if (isset($_POST['Reservation'])) {
         $model->load(Yii::$app->request->post());
         if (isset($_POST['Reservation']['id']) && $_POST['Reservation']['id'] != null) {
             $model = Reservation::findOne($_POST['Reservation']['id']);
             $showDetail = true;
         }
     }
     return $this->render('detailDependentDropdown', ['model' => $model, 'showDetail' => $showDetail]);
 }
 public function actionCreateCustomerAndReservation()
 {
     $customer = new Customer();
     $reservation = new Reservation();
     $reservation->customer_id = 0;
     if ($customer->load(Yii::$app->request->post()) && $reservation->load(Yii::$app->request->post()) && $customer->validate() && $reservation->validate()) {
         $dbTrans = Yii::$app->db->beginTransaction();
         $customerSaved = $customer->save();
         if ($customerSaved) {
             $reservation->customer_id = $customer->id;
             $reservationSaved = $reservation->save();
             if ($reservationSaved) {
                 $dbTrans->commit();
             } else {
                 $dbTrans->rollback();
             }
         } else {
             $dbTrans->rollback();
         }
     }
     return $this->render('createCustomerAndReservation', ['customer' => $customer, 'reservation' => $reservation]);
 }
 public function actionCreateCustomerAndReservation()
 {
     $customer = new \app\models\Customer();
     $reservation = new \app\models\Reservation();
     // It is useful to set fake customer_id to reservation model to avoid validationerror (because customer_id is mandatory)
     $reservation->customer_id = 0;
     if ($customer->load(Yii::$app->request->post()) && $reservation->load(Yii::$app->request->post()) && $customer->validate() && $reservation->validate()) {
         $dbTrans = Yii::$app->db->beginTransaction();
         $customerSaved = $customer->save();
         if ($customerSaved) {
             $reservation->customer_id = $customer->id;
             $reservationSaved = $reservation->save();
             if ($reservationSaved) {
                 $dbTrans->commit();
             } else {
                 $dbTrans->rollback();
             }
         } else {
             $dbTrans->rollback();
         }
     }
     return $this->render('createCustomerAndReservation', ['customer' => $customer, 'reservation' => $reservation]);
 }