You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.1 KiB
80 lines
2.1 KiB
<?php
|
|
|
|
namespace common\models;
|
|
|
|
use yii\base\Model;
|
|
use yii\data\ActiveDataProvider;
|
|
use common\models\Category;
|
|
|
|
/**
|
|
* CategorySearch represents the model behind the search form of `\common\models\Category`.
|
|
*/
|
|
class CategorySearch extends Category {
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function rules() {
|
|
return [
|
|
[['cat_name','id', 'icon_type', 'sort_order', 'created_at', 'updated_at'], 'integer'],
|
|
[['cat_name', 'icon', 'description'], 'safe'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function scenarios() {
|
|
// bypass scenarios() implementation in the parent class
|
|
return Model::scenarios();
|
|
}
|
|
|
|
/**
|
|
* Creates data provider instance with search query applied
|
|
*
|
|
* @param array $params
|
|
*
|
|
* @return ActiveDataProvider
|
|
*/
|
|
public function search($params) {
|
|
$query = Category::find();
|
|
|
|
// add conditions that should always apply here
|
|
|
|
$dataProvider = new ActiveDataProvider([
|
|
'query' => $query,
|
|
'pagination' => [
|
|
'pageSizeLimit' => [1, 200]
|
|
],
|
|
'sort' => [
|
|
'defaultOrder' => [
|
|
'id' => SORT_DESC,
|
|
]
|
|
],
|
|
]);
|
|
|
|
$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,
|
|
'icon_type' => $this->icon_type,
|
|
'sort_order' => $this->sort_order,
|
|
'created_at' => $this->created_at,
|
|
'updated_at' => $this->updated_at,
|
|
]);
|
|
|
|
$query->andFilterWhere(['like', 'cat_name', $this->cat_name])
|
|
->andFilterWhere(['like', 'icon', $this->icon])
|
|
->andFilterWhere(['like', 'description', $this->description]);
|
|
|
|
return $dataProvider;
|
|
}
|
|
|
|
}
|