Собственно не работают фильтры GridView в Yii2 (на мои действия не подают признаки жизни). Мой код:
Контроллер
public function actionIndex()
{
$searchModel = new UserSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
Модель поиска
public function search($params)
{
$query = StUsers::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,
'passport_number' => $this->passport_number,
'passport_issue' => $this->passport_issue,
'passport_validity' => $this->passport_validity,
'dob' => $this->dob,
'discount' => $this->discount,
'block' => $this->block,
'block_admin_id' => $this->block_admin_id,
'register_date' => $this->register_date,
'alive' => $this->alive,
]);
$query->andFilterWhere(['like', 'fullname', $this->fullname])
->andFilterWhere(['like', 'passport_serie', $this->passport_serie])
->andFilterWhere(['like', 'passport_authority', $this->passport_authority])
->andFilterWhere(['like', 'sex', $this->sex])
->andFilterWhere(['like', 'residence_address', $this->residence_address])
->andFilterWhere(['like', 'phone_number', $this->phone_number])
->andFilterWhere(['like', 'password', $this->password])
->andFilterWhere(['like', 'email', $this->email])
->andFilterWhere(['like', 'block_reason', $this->block_reason]);
return $dataProvider;
}
Представление
<?php Pjax::begin(); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'id',
'fullname'
]); ?>
<?php Pjax::end(); ?>