Ejemplo n.º 1
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($this->is_insert) {
         foreach (self::$required_fields as $f) {
             $tour_meta = new ToursMeta();
             $tour_meta->tour_id = $this->id;
             $tour_meta->tour_key = $f;
             $tour_meta->tour_value = 'int';
             $tour_meta->description = str_replace('_', ' ', $f);
             $tour_meta->save();
         }
     }
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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]);
     }
 }
Ejemplo n.º 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMeta()
 {
     return $this->hasOne(ToursMeta::className(), ['id' => 'meta_id']);
 }
 /**
  * Finds the ToursMeta model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return ToursMeta the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = ToursMeta::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }