Underscore "_" Doesnt Work In Cgridview Search

Hello everyone.

i have a problem in CGridView with filters.

I have some columns that have data with underscores, like “125_120”. And when i put the underscore in filters, the framework can’t find anything… Seems to be a problem with encoding.

Here is the example:





I will appreciate any help :)

bump to the top…

The actual filtering is done in the model->search() method… how are you using that value there?

Im doing as Yii framework generates crude…

My admin.php (where there is the CGridView)

$this->widget('zii.widgets.grid.CGridView', array(






What I asked is what are you doing with the entered value in the $model->search() method ?

I didnt understand your question since i didn’t invent anything…

btw here is the code:

public function search()


		$criteria=new CDbCriteria;



		if(strpos($this->NCODE, '%') === false)

			$criteria->compare('LOWER(NCODE)', strtolower($this->NCODE), false);


			$criteria->compare('LOWER(NCODE)', strtolower(str_replace('%', '', $this->NCODE)), true);


		$criteria->compare('LOWER(NDESC)', strtolower($this->NDESC), true);

		$criteria->compare('LOWER(ECODE)', strtolower($this->ECODE), false);

		$criteria->compare('LOWER(EDESC)', strtolower($this->EDESC), true);

		$criteria->compare('LOWER(ACCAO)', strtolower($this->ACCAO), true);

		$criteria->compare('LOWER(RESPONSAVEL)', strtolower($this->RESPONSAVEL), true);

		$criteria->compare('LOWER(ACCAORECURSO)', strtolower($this->ACCAORECURSO), true);

		$criteria->compare('LOWER(RESPONSAVELRECURSO)', strtolower($this->RESPONSAVELRECURSO), true);

		$criteria->compare('LOWER(EVENTSTATUS)', strtolower($this->EVENTSTATUS), true);

		$criteria->compare('LOWER(SERVICE)', strtolower($this->SERVICE), true);

		$criteria->compare('LOWER(OPERATION)', strtolower($this->OPERATION), true);


		return new CActiveDataProvider($this, array(







Just added some validation in generated model from crude (added strtolower validations).

My actionAdmin from controller is exactly the same:

public function actionAdmin()


		$model=new FW_STATUS_TRANSLATE('search');

		$model->unsetAttributes();  // clear any default values







Thank you for your time :)

So… the $model-search() method is the one that makes the database search and returns the filtered data when you enter something on the filter input field.

The method you posted above is from the model that is shown on the grid (FW_STATUS_TRANSLATE)?

On your first post, on the pictures, the column name is "Val Dest"… what is the variable (field name) for that column?

Sorry Maurizio, I mistake the models… From the pictures the correct model is EAI_TMAPEAMENTO

Here is the code of $model->search():

public function search()


		// Warning: Please modify the following code to remove attributes that

		// should not be searched.

		$criteria=new CDbCriteria;








		return new CActiveDataProvider($this, array(



				'defaultOrder'=>'ID_SEQ, ENTIDADE, ATRIBUTO ASC',







The code is exactly as the generated from yii. The action in controller is the same as above but for EAI_TMAPEAMENTO :)

So the actual line that process that field is this one


from the BIG filed names I presume you are using MSSQL or ORACLE… From what I know in MSSQL the underscore is a wildchar (probably the same in oracle) , not in mysql that’s why in mysql this works.

If that is the case you need to escape the underscore characters so to actually search for a literal underscore.

Yes my DB is oracle.

Found the solution for "escape" characters in this guide

Oracle Escape Characters

Thank you for your time Maurizio :)