banki.test/models/ParameterSearch.php

47 lines
924 B
PHP
Raw Permalink Normal View History

2024-08-20 06:27:17 +02:00
<?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();
2024-08-20 06:27:17 +02:00
$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;
}
}