Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Matching Multiple Values In Cdbcriteria

$
0
0
So we have a text entry for our model where the user enters a city.
$model->city


We then have a search.
We want the user to be able to search for multiple cities
(e.g. comma separated list).

This code works fine for one city:
$criteria->compare('city',$this->city,true);


So then I went and tried this for the multiple match:
if ($this->city) {
   if (strpos($this->city,',') !==false) {
	$cities = explode(',',$this->city);		  
	foreach($cities as $c) {
		$criteria->compare('city',$c,true);
                //I also tried things like $criteria->compare('city',$c,true,"AND",true);
	} 
   } else {
     $criteria->compare('city',$this->city,true);
   }
		}


But it doesn't work - the search returns no elements as soon as we have a comma separated list of values.
Any ideas on how to resolve this?

Thank you

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>