/** * Lists all TourField models. * @return mixed */ public function actionIndex() { $params = Yii::$app->request->queryParams; if (empty($params['TourFieldSearch']['tour_id'])) { $params['TourFieldSearch']['tour_id'] = Tour::find()->one()->id; } $searchModel = new TourFieldSearch(); $dataProvider = $searchModel->search($params); $dataProvider->pagination->setPageSize(-1); $dataProvider->sort = false; $tour = Tour::findOne(['id' => $searchModel->tour_id]); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'tour' => $tour]); }
/** * Creates a new Booking model. * If creation is successful, the browser will be redirected to the 'view' page. * @param null $tour_id * @return mixed */ public function actionCreate($tour_id = null) { if ($tour_id === null) { return $this->render('create-step1', ['tours' => Tour::find()->all()]); } $model = new Booking(); $model->tour_id = $tour_id; $model = new BookingEx($model); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Tour::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * Finds the Tour model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Tour the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Tour::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
<?php use backend\models\Tour; use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii\widgets\ActiveForm; /* @var $this yii\web\View */ /* @var $model backend\models\TourFieldSearch */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="tour-field-search"> <?php $form = ActiveForm::begin(['action' => ['index'], 'method' => 'get']); ?> <?php echo $form->field($model, 'tour_id')->dropDownList(ArrayHelper::map(Tour::find()->all(), 'id', 'title'), ['onchange' => 'this.form.submit()']); ?> <?php ActiveForm::end(); ?> </div>
public function getTour() { return $this->hasOne(Tour::className(), ['id' => 'tour_id']); }