How can i query from model with multiple values in 1 condition

i wanna write some query statement like this statement in YII2.0

this below code is wrong but i wanna write it like this syntax

Thank you

Probably you don’t need to modify “search” method of your PensSearch.

I guess it should already have something like the following:

$query->andFilterWhere('PEN_MODEL', $this->PEN_MODEL);

It will do the following:


[*] If $this->PEN_MODEL is empty, it will do nothing.

[*] If $this->PEN_MODEL is a scalar value, it will add " WHERE PEN_MODEL = ‘something’" to the query.

[*] If $this->PEN_MODEL is an array, it will add " WHERE PEN_MODEL in (A,B,C,…X)" to the query.


Take a look at these items in the API reference.




Is ‘PEN_MODEL’ a string? Then it’s a bit different.

// $query->andFilterWhere('like', 'PEN_MODEL', $this->PEN_MODEL);

$query->andFilterWhere('or like', 'PEN_MODEL', $this->PEN_MODEL);

It’s work, Thank you so much