/** * @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); }
/** * @param $id * @return $this|array */ public function actionUpdate($id) { $app = Yii::$app; $request = $app->request; $response = $app->response; /* @var $model HotelRecord */ $model = TourRecord::findOne($id); $model->setScenario('update'); if ($model->load($request->post())) { if ($request->isAjax) { $response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->save()) { return $response->redirect(['tour/index']); } } return $this->render('update', ['model' => $model]); }
<?php echo $form->field($hotelFilterForm, 'country_id')->dropDownList(CountryRecord::getCountries())->label(false); ?> <?php echo $form->field($search, 'hotel_id')->dropDownList(HotelRecord::getHotels())->label(false); ?> <?php echo $form->field($hotelFilterForm, 'stars')->dropDownList(HotelRecord::stars())->label(false); ?> <?php echo $form->field($hotelFilterForm, 'type')->dropDownList(HotelRecord::types())->label(false); ?> <?php echo $form->field($search, 'adults')->dropDownList(TourRecord::adults())->label(false); ?> <?php echo $form->field($search, 'children')->dropDownList(TourRecord::children())->label(false); ?> <div class="form-group"> <div class="input-group"> <?php echo \yii\helpers\Html::submitButton('Применить', array('class' => 'btn btn-warning', 'style' => 'margin-bottom: 9px')); ?> </div> </div> </div> <?php \yii\widgets\ActiveForm::end(); ?> </div>
<?php use common\models\tour\TourRecord; use yii\bootstrap\ActiveForm; $form = ActiveForm::begin(['layout' => 'horizontal']); echo $form->field($model, 'name'); echo $form->field($model, 'hotel_id')->dropDownList(\common\models\hotel\HotelRecord::getHotels()); echo $form->field($model, 'children')->dropDownList(TourRecord::children()); echo $form->field($model, 'adults')->dropDownList(TourRecord::adults()); $clientOptions = ['format' => 'DD.MM.YYYY HH:mm:ss']; $clientOptions['minDate'] = new \yii\web\JsExpression('moment().format("MM.DD.YYYY")'); $options = ['placeholder' => 'дд.мм.гггг ЧЧ:ММ']; if ($model->isNewRecord) { $options['value'] = Yii::$app->formatter->datetimeFormat; $clientOptions['minDate'] = new \yii\web\JsExpression('moment().format("MM.DD.YYYY")'); } echo $form->field($model, 'flyAt')->widget(\backend\widgets\DateTimePicker::className(), ['options' => $options, 'language' => 'ru', 'clientOptions' => $clientOptions]); ?> <div class="clearfix form-actions"> <div class="col-md-offset-3 col-md-9"> <?php echo \yii\bootstrap\Html::submitButton('Применить', ['class' => 'btn btn-success']); ?> </div> </div> <?php ActiveForm::end();