Search across related models via CGridView

I’m trying to create an Admin section that will allow admins to search over a model (“Child”), which is related to another model called “Parent”.

But I can’t figure out:

  1. How to pass in the related model (“parent”) in the filter, so admins may search in the textfield that’s rendered

  2. How to allow admins to use the Advanced Search for the parent

My view:

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








	  'parent.title:text:Parent Title',



)); ?>

My relations function in "Child":

public function relations()


	return array(

           'parent' => array(self::BELONGS_TO, 'ParentModel', 'parent_id'),



My search function in my "Child" model:

public function search() {

	$criteria=new CDbCriteria;

        $criteria->with = array(









	return new CActiveDataProvider(get_class($this), array('criteria'=>$criteria,




I’ve even played around with declaring:

public $parentTitle=’’;

as a variable of my Child model class.


This has already been discussed a couple times, please check this for relevant topics about it.

Thanks. Yea, I searched before I posted, but still couldn’t figure it out… so finally decided to post.

Turns out, I tried a solution previously posted (that should have worked) but it didn’t work for me because I didn’t put the column ‘value’ in single quotes. I knew it was some small thing that I overlooked.






Thanks. All good now!