(YII2)How to make AR search when searching for multiple values in one parameter?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
94 views
Good time of day.

Required to solve the problem: in search of AR for the time you need to process more than 1 value to find the parameter.

There is a column of the city. In search enter: Kazan, Samara, Rostov, etc. through the separator. Search handles each of the cities and taking the match.

In the model Search to organize too much, the foreach did not work. Broke the query using 'explode' at the comma and sent in a loop.
foreach ($array as $city_str) { $query->andFilterWhere(['like', 'city', $city_str]);


Prompt, in what side to dig?
by | 94 views

2 Answers

0 like 0 dislike
I understand that is
andFilterWhere
must be
orFilterWhere
or most likely because:
$query->andFilterWhere(['or', ['like', 'city', $city_str1], ['like', 'city', $city_str2], .... ['like', 'city', $city_str999], ]);

Because Your option you will find the city only if it is called something like "the Kazan-Samara-Rostov"
by
0 like 0 dislike
->where(['city' => $cities])->all();
where $cities - list of cities (an array).
The problem occurs as soon as you need fuzzy search (value).
by

Related questions

0 like 0 dislike
2 answers
asked May 11, 2019 by dauren101
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
36,634 users