L
L
Lander2015-09-17 11:20:50
Yii
Lander, 2015-09-17 11:20:50

How to write "left" and "right" LIKE in ActiveQuery Yii2?

Good afternoon.
I have a very stupid question, but only Yii1 is described in Google, but it does not work on Yii2.

$users = \common\models\User::find()->filterWhere(['like', 'username', '89'])->all();

Forms something like:
...`username` LIKE '%89%'...
And I need
...`username` LIKE '89%'...
How to do this in Yii2?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Pavlenko, 2015-09-17
@usdglander

www.yiiframework.com/doc-2.0/yii-db-query.html#whe...
For example, ['like', 'name', '%tester', false] will generate name LIKE '%tester'.
That is, you just need to write ['like', 'username', '89%', false]
Conclusion - read the documentation carefully.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question