tacos_tacos_tacos
tacos_tacos_tacos

Reputation: 10585

Yii findAll that match at least one of several criteria

I am implementing a simpleQuery action in Yii to findAll records that match at least one of several CDbCriteria or if necessary, just some search conditions. For example, I want the user to be able to query my records by typing in one string. That string should be checked against each of four columns, and the result set should include all records that have at least one column matched against the string (with no duplicates). I'm still new to Yii so any help is greatly appreciated.

Upvotes: 0

Views: 1687

Answers (1)

Mukesh Soni
Mukesh Soni

Reputation: 6668

Assuming that you have the search input in $search_input field of the model and you want to search all of the three fields - name, title and desc, for that string, you can do -

$criteria = new CDbCriteria();
$criteria->compare('name', $this->search_input, TRUE, 'OR');
$criteria->compare('title', $this->search_input, TRUE, 'OR');
$criteria->compare('desc', $this->serach_input, TRUE, 'OR');
$result = MyModel::model()->findAll($criteria);

Upvotes: 2

Related Questions