1 | <?php |
||
21 | trait QueryTrait |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * Attach like condition. |
||
26 | * @param mixed $value |
||
27 | * @param string $attribute |
||
28 | * @param string|false $like |
||
29 | * @return $this |
||
30 | */ |
||
31 | 17 | protected function likeCondition($value, $attribute, $like = false) |
|
32 | { |
||
33 | 17 | if (!is_string($attribute)) { |
|
34 | 2 | return $this; |
|
35 | } |
||
36 | 17 | if ($like) { |
|
|
|||
37 | 5 | return $this->andWhere([$like, $attribute, $value]); |
|
38 | } |
||
39 | 16 | return $this->andWhere([$attribute => $value]); |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * Specify range wilth $attribute to $query. |
||
44 | * @param \yii\db\ActiveQuery $query |
||
45 | * @param string $attribute |
||
46 | * @param string $start |
||
47 | * @param string $end |
||
48 | * @return $query |
||
49 | */ |
||
50 | 1 | protected static function range($query, $attribute, $start = null, $end = null) |
|
60 | } |
||
61 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: