If you use a model generated with gii (or yiic shell) by one of the last version of framework,
there should already be the function search() in the model.
The function search of a model is smth like that:
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
public function search()
// Warning: Please modify the following code to remove attributes that
// should not be searched.
return new CActiveDataProvider(get_class($this), array(
This function returns a CDbCriteria on wich has been many time called the function compare. This function adds some condition to the where of the query, so it will look like “WHERE NOME LIKE ‘%$this->NOME%’ AND COGNOME LIKE ‘%$this->COGNOME%’”.
so, in the controller there should be smth like that:
public function actionSearch()
//return the dataProvider with all comparison
'criteria'=>$dataProvider->criteria // the criteria, from data provider
I mistook in my previous post, because the search function returns a CActiveDataProvider, not a CDbCriteria. Anyway you can get the CDbCriteria from the dataProvider easily.
At this point in the view you can write your dropdownlist like that:
Please be advised that I didn’t tested this code, I just copied from different files and contextualize a bit, so there can be sintax error. Is just an idea about what is the best practice (or, al least, how the framework is usually doing)