banki.test/models/ParameterSearch.php

47 lines
955 B
PHP

<?php
namespace app\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
class ParameterSearch extends Parameter
{
public $id;
public $title;
public function rules()
{
return [
[[ 'id' ], 'integer' ],
[[ 'title' ], 'string' ]
];
}
public function scenarios()
{
return Model::scenarios();
}
public function search($params): ActiveDataProvider
{
$query = Parameter::find();//->with(['icon', 'iconGray']);
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
if ($this->title) {
$query->andFilterWhere(['like', 'title', $this->title]);
}
if ($this->id) {
$query->andFilterWhere(['like', 'id', $this->id]);
}
return $dataProvider;
}
}