예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ToursMeta::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, 'tour_id' => $this->tour_id, 'order_sort' => $this->order_sort]);
     $query->andFilterWhere(['like', 'tour_key', $this->tour_key])->andFilterWhere(['like', 'tour_value', $this->tour_value])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
예제 #2
0
 /**
  * Updates an existing Tours model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $tour_meta = new ToursMeta();
     $tour_meta = $tour_meta->getFields($model->id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         foreach ($_POST['Meta'] as $meta => $val) {
             $meta = ToursMeta::find()->where('tour_key=:tour_key', [':tour_key' => $meta])->andWhere('tour_id=:tour_id', [':tour_id' => $model->id])->one();
             $meta->order_sort = $val;
             if (!$meta->save()) {
                 var_dump($meta->errors);
                 die;
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'tour_meta' => $tour_meta]);
     }
 }