コード例 #1
0
ファイル: TourController.php プロジェクト: lebeddima/booking
 /**
  * @return array|string
  */
 public function actionCreate()
 {
     $model = new TourRecord();
     $model->setScenario('create');
     $request = Yii::$app->request;
     if ($model->load($request->post())) {
         if ($request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
         if ($model->save()) {
             return $this->redirect(['tour/index']);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
コード例 #2
0
ファイル: TourController.php プロジェクト: lebeddima/booking
 /**
  * @return array|string
  */
 public function actionIndex()
 {
     $app = \Yii::$app;
     $request = $app->request;
     $search = new TourRecord();
     $search->setScenario('search');
     $hotelFilterForm = new HotelFilterForm();
     if (Yii::$app->request->isAjax && $hotelFilterForm->load($request->get())) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($hotelFilterForm);
     }
     $hotelFilterForm->load($request->get());
     $hotelFilterForm->validate();
     $params = ArrayHelper::merge($request->getQueryParams(), [$search->formName()]);
     $options = ['country_id' => $hotelFilterForm->country_id, 'stars' => $hotelFilterForm->stars, 'type' => $hotelFilterForm->type];
     $dataProvider = $search->getFilterDataProvider($options, $params);
     $viewData = ['dataProvider' => $dataProvider, 'totalCount' => $dataProvider->totalCount, 'hotelFilterForm' => $hotelFilterForm, 'search' => $search];
     return $this->render('index', $viewData);
 }