CommentsSearch.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace control\models;
  3. use yii\base\Model;
  4. use yii\data\ActiveDataProvider;
  5. use manager\models\Comments;
  6. /**
  7. * AuthorsSearch represents the model behind the search form of `app\models\Authors`.
  8. */
  9. class CommentsSearch extends Comments
  10. {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function rules()
  15. {
  16. return [
  17. [['id'], 'integer'],
  18. [['message', 'ip_address', 'user_agent', 'fakename', 'created_at'], 'safe'],
  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 = Comments::find();
  39. // add conditions that should always apply here
  40. $dataProvider = new ActiveDataProvider([
  41. 'query' => $query,
  42. 'pagination' => [
  43. 'pageSize' => 70
  44. ],
  45. 'sort' =>
  46. [
  47. 'defaultOrder' => [
  48. 'id' => SORT_DESC,
  49. ],
  50. 'attributes' => ['id'],
  51. ],
  52. ]);
  53. $this->load($params);
  54. if (!$this->validate()) {
  55. // uncomment the following line if you do not want to return any records when validation fails
  56. // $query->where('0=1');
  57. return $dataProvider;
  58. }
  59. // grid filtering conditions
  60. $query->andFilterWhere([
  61. 'id' => $this->id,
  62. ]);
  63. $query->andFilterWhere(['like', 'message', $this->message])
  64. ->andFilterWhere(['like', 'ip_address', $this->ip_address])
  65. ->andFilterWhere(['like', 'user_agent', $this->user_agent])
  66. ->andFilterWhere(['like', 'created_at', $this->created_at])
  67. ->andFilterWhere(['like', 'fakename', $this->fakename]);
  68. return $dataProvider;
  69. }
  70. }