CategoriesblogSearch.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\models;
  3. use Yii;
  4. use yii\base\Model;
  5. use yii\data\ActiveDataProvider;
  6. use app\models\Categoriesblog;
  7. class CategoriesblogSearch extends Categoriesblog
  8. {
  9. /**
  10. * @inheritdoc
  11. */
  12. public function rules()
  13. {
  14. return [
  15. [['id'], 'integer'],
  16. [['title', 'description', 'key_words'], 'safe'],
  17. ];
  18. }
  19. /**
  20. * @inheritdoc
  21. */
  22. public function scenarios()
  23. {
  24. // bypass scenarios() implementation in the parent class
  25. return Model::scenarios();
  26. }
  27. /**
  28. * Creates data provider instance with search query applied
  29. *
  30. * @param array $params
  31. *
  32. * @return ActiveDataProvider
  33. */
  34. public function search($params)
  35. {
  36. $query = Categoriesblog::find();
  37. // add conditions that should always apply here
  38. $dataProvider = new ActiveDataProvider([
  39. 'query' => $query,
  40. ]);
  41. $this->load($params);
  42. if (!$this->validate()) {
  43. // uncomment the following line if you do not want to return any records when validation fails
  44. // $query->where('0=1');
  45. return $dataProvider;
  46. }
  47. // grid filtering conditions
  48. $query->andFilterWhere([
  49. 'id' => $this->id,
  50. ]);
  51. $query->andFilterWhere(['like', 'title', $this->title])
  52. ->andFilterWhere(['like', 'description', $this->description])
  53. ->andFilterWhere(['like', 'key_words', $this->key_words]);
  54. return $dataProvider;
  55. }
  56. }