Table Search


I’ve an admin manage table with search input. The input in the table is stored as an ID, but it displays the corresponding text.


ID | DOMAIN     |  HOST    |


[ ]| [        ] | [       ]


12 | | (stored as 3)


Yahoo is stored in the database as a integer, but I don’t want to search on integers, but on text. So if I search for yah, I get all hosts that contain yah in it!

Can someone help me?



Please show your code that prepares criteria for CActiveDataProvider.

Oh sorry about that! Here is the part of the code where the table is displayed, I deleted some parts to make it more organized.


/* @var $this DomainController */

/* @var $model Domain */

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








                     'name' => 'primary_url_id',

                     'header' => 'Primary URL',

                     'value' => '$data->domain->url',






)); ?>

I think the answer is in this part of code, this is the Domain model:

	public function search()


		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;



		$criteria->compare('primary_url_id',$this->primary_url_id, true);

		return new CActiveDataProvider($this, array(





$criteria->compare('primary_url_id',$this->primary_url_id, true);


$criteria->compare('domain.url',$this->primary_url_id, true);

// 'together' will force a left join, that's extra cost for searching in relations

$criteria->with = array('domain'=>array('together'=>true)); 

Just make sure that the ‘primary_url_id’ attribute is not limited to integers in the ‘search’ scenario. I know this looks strange but is it’s valid anyway.

Thanks! It works now!

Please post question in General Discussion for Yii 1.1.x rather than Yii-powered Apps