6 use yii\data\ActiveDataProvider;
11 * ModelsSearch represents the model behind the search form of `app\models\Models`.
13 class ModelsSearch extends Models
18 public function rules()
21 [['id', 'type_id'], 'integer'],
22 [['name', 'modelnumber', 'product', 'typeName'], 'safe'],
29 public function scenarios()
31 // bypass scenarios() implementation in the parent class
32 return Model::scenarios();
36 * Creates data provider instance with search query applied
38 * @param array $params
40 * @return ActiveDataProvider
42 public function search($params)
44 $query = Models::find()
45 ->select(Models::tableName().'.*, ' . Types::tableName() . '.name AS typeName')
46 ->joinWith([ 'types' ]);
48 // add conditions that should always apply here
50 $dataProvider = new ActiveDataProvider([
54 $dataProvider->setSort([
60 $dataProvider->sort->attributes['typeName'] = [
61 'asc' => [ Types::tableName() . '.name' => SORT_ASC ],
62 'desc' => [ Types::tableName() . '.name' => SORT_DESC ],
68 if (!$this->validate()) {
69 // uncomment the following line if you do not want to return any records when validation fails
70 // $query->where('0=1');
74 // grid filtering conditions
75 $query->andFilterWhere([
77 'type_id' => $this->type_id,
80 $query->andFilterWhere([ 'ilike', Models::tablename() . '.name', $this->name ])
81 ->andFilterWhere([ 'ilike', 'modelnumber', $this->modelnumber ])
82 ->andFilterWhere([ 'ilike', 'product', $this->product ])
83 ->andFilterWhere([ 'ilike', Types::tableName() . '.name', $this->typeName ]);