AuthorsSearch.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\models;
  3. use yii\base\Model;
  4. use yii\data\ActiveDataProvider;
  5. use app\models\Authors;
  6. /**
  7. * AuthorsSearch represents the model behind the search form of `app\models\Authors`.
  8. */
  9. class AuthorsSearch extends Authors
  10. {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function rules()
  15. {
  16. return [
  17. [['id'], 'integer'],
  18. [['uid', 'name', 'url', 'jobTitle', 'phone', 'active'], '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 = Authors::find();
  39. // add conditions that should always apply here
  40. $dataProvider = new ActiveDataProvider([
  41. 'query' => $query,
  42. ]);
  43. $this->load($params);
  44. if (!$this->validate()) {
  45. // uncomment the following line if you do not want to return any records when validation fails
  46. // $query->where('0=1');
  47. return $dataProvider;
  48. }
  49. // grid filtering conditions
  50. $query->andFilterWhere([
  51. 'id' => $this->id,
  52. ]);
  53. $query->andFilterWhere(['like', 'uid', $this->uid])
  54. ->andFilterWhere(['like', 'name', $this->name])
  55. ->andFilterWhere(['like', 'url', $this->url])
  56. ->andFilterWhere(['like', 'jobTitle', $this->jobTitle])
  57. ->andFilterWhere(['like', 'phone', $this->phone])
  58. ->andFilterWhere(['like', 'active', $this->active]);
  59. return $dataProvider;
  60. }
  61. }