PolicySearch.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace backend\models\search;
  3. use common\models\Policy;
  4. use yii\base\Model;
  5. use yii\data\ActiveDataProvider;
  6. /**
  7. * PolicySearch represents the model behind the search form about `common\models\Policy`.
  8. */
  9. class PolicySearch extends Policy
  10. {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function rules()
  15. {
  16. return [
  17. [['id'], 'integer'],
  18. [['title', 'type', 'cengci', 'estate'], 'string'],
  19. ];
  20. }
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public function scenarios()
  25. {
  26. // bypass scenarios() implementation in the parent class
  27. return Model::scenarios();
  28. }
  29. /**
  30. * Creates data provider instance with search query applied.
  31. *
  32. * @param array $params
  33. *
  34. * @return ActiveDataProvider
  35. */
  36. public function search($params)
  37. {
  38. $query = Policy::find();
  39. $dataProvider = new ActiveDataProvider([
  40. 'query' => $query,
  41. 'sort' => [
  42. 'defaultOrder' => [
  43. 'sort' => SORT_ASC
  44. ]
  45. ]
  46. ]);
  47. $this->load($params);
  48. if (!$this->validate()) {
  49. // uncomment the following line if you do not want to return any records when validation fails
  50. // $query->where('0=1');
  51. return $dataProvider;
  52. }
  53. $query->andFilterWhere([
  54. 'id' => $this->id,
  55. 'estate' => $this->estate,
  56. ]);
  57. $query->andFilterWhere(['like', 'title', $this->title]);
  58. $query->andFilterWhere(['like', 'type', $this->type]);
  59. $query->andFilterWhere(['like', 'cengci', $this->cengci]);
  60. return $dataProvider;
  61. }
  62. }