1 | <?php |
||
23 | trait SearchModelTrait |
||
24 | { |
||
25 | public static $filterConditions = ['in', 'like', 'gt', 'ge', 'lt', 'le']; |
||
26 | |||
27 | public function attributes() |
||
31 | |||
32 | protected function searchAttributes() |
||
33 | { |
||
34 | static $attributes = []; |
||
35 | |||
36 | if ($attributes === []) { |
||
37 | foreach (parent::attributes() as $attribute) { |
||
|
|||
38 | $attributes = array_merge($attributes, $this->buildAttributeConditions($attribute)); |
||
39 | } |
||
40 | } |
||
41 | |||
42 | return $attributes; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Builds all possible $attribute names using [[$filterConditions]]. |
||
47 | * |
||
48 | * @param $attribute |
||
49 | * @return array |
||
50 | */ |
||
51 | protected function buildAttributeConditions($attribute) |
||
52 | { |
||
53 | $attributes = []; |
||
54 | foreach (array_merge([''], static::$filterConditions) as $condition) { |
||
55 | $attributes[] = $attribute . ($condition === '' ? '' : "_$condition"); |
||
56 | } |
||
57 | return $attributes; |
||
58 | } |
||
59 | |||
60 | public function rules() |
||
67 | |||
68 | public function scenarios() |
||
69 | { |
||
73 | |||
74 | /** |
||
75 | * Creates data provider instance with search query applied. |
||
76 | * @param $params |
||
77 | * @param array $dataProviderConfig |
||
78 | * @throws \yii\base\InvalidConfigException |
||
79 | * @return ActiveDataProvider |
||
80 | */ |
||
81 | public function search($params, $dataProviderConfig = []) |
||
122 | } |
||
123 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.