OSDN Git Service

Изменено меню
[invent/invent.git] / models / StatusSearch.php
1 <?php
2
3 namespace app\models;
4
5 use yii\base\Model;
6 use yii\data\ActiveDataProvider;
7 use app\models\Status;
8
9 /**
10  * StatusSearch represents the model behind the search form of `app\models\Status`.
11  */
12 class StatusSearch extends Status
13 {
14     /**
15      * {@inheritdoc}
16      */
17     public function rules()
18     {
19         return [
20             [['id'], 'integer'],
21             [['name'], 'safe'],
22         ];
23     }
24
25     /**
26      * {@inheritdoc}
27      */
28     public function scenarios()
29     {
30         // bypass scenarios() implementation in the parent class
31         return Model::scenarios();
32     }
33
34     /**
35      * Creates data provider instance with search query applied
36      *
37      * @param array $params
38      *
39      * @return ActiveDataProvider
40      */
41     public function search($params)
42     {
43         $query = Status::find();
44
45         // add conditions that should always apply here
46
47         $dataProvider = new ActiveDataProvider([
48             'query' => $query,
49         ]);
50
51         $dataProvider->setSort([
52             'defaultOrder' => [
53                 'name' => SORT_ASC,
54             ],
55         ]);
56
57         $this->load($params);
58
59         if (!$this->validate())
60         {
61             // uncomment the following line if you do not want to return any records when validation fails
62             // $query->where('0=1');
63             return $dataProvider;
64         }
65
66         // grid filtering conditions
67         $query->andFilterWhere([
68             'id' => $this->id,
69         ]);
70
71         $query->andFilterWhere(['ilike', 'name', $this->name]);
72
73         return $dataProvider;
74     }
75 }