コード例 #1
0
ファイル: RegionSearch.php プロジェクト: phanthehung/onepx
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Region::find();
     $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;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'photo_id' => $this->photo_id, 'sort_order' => $this->sort_order, 'state' => $this->state, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'abbreviation', $this->abbreviation])->andFilterWhere(['like', 'wikipedia_api', $this->wikipedia_api]);
     return $dataProvider;
 }
コード例 #2
0
ファイル: SiteController.php プロジェクト: phanthehung/onepx
 /**
  * Updates an existing Region 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);
     if ($model->load(Yii::$app->request->post())) {
         $model->updated_at = date("Y-m-d H:i:s");
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->redirect(['update', 'id' => $model->id]);
         }
     } else {
         $user = UserAccount::find()->select('id, username')->all();
         $regions = Region::find()->select('id,title')->all();
         return $this->render('update', ['user' => $user, 'model' => $model, 'regions' => $regions]);
     }
 }