/
peyli
/
Practice
Обзор
Документация
Войти
/
peyli
/
Practice
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
models/EventSearch.php
79 строк
2 KB
Катя
Полный код
27 июн 2026, 14:28
27 июн 2026, 14:28
6181a72
Код
Авторство
О чём код?
<?php namespace app\models; use yii\base\Model; use yii\data\ActiveDataProvider; use app\models\Event; /** * EventSearch represents the model behind the search form of `app\models\Event`. */ class EventSearch extends Event { /** * {@inheritdoc} */ public function rules() { return [ [['id', 'price'], 'integer'], [['title', 'user_username', 'event_type', 'place', 'description', 'cover', 'start', 'end', 'status', 'created_at'], '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 * @param string|null $formName Form name to be used into `->load()` method. * * @return ActiveDataProvider */ public function search($params, $formName = null) { $query = Event::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params, $formName); 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, 'price' => $this->price, 'start' => $this->start, 'end' => $this->end, 'created_at' => $this->created_at, ]); $query->andFilterWhere(['like', 'title', $this->title]) ->andFilterWhere(['like', 'user_username', $this->user_username]) ->andFilterWhere(['like', 'event_type', $this->event_type]) ->andFilterWhere(['like', 'place', $this->place]) ->andFilterWhere(['like', 'description', $this->description]) ->andFilterWhere(['like', 'cover', $this->cover]) ->andFilterWhere(['like', 'status', $this->status]); return $dataProvider; } }