CGridView filter with relations

Hi, everybody!
I have solved this problem.
We have a related column: this->table_name->related_column
It's so easy:
1. Add public $var_name in your model
2. In model method search() add:
$criteria->with = 'table_name';
$criteria->compare('table_name.related_column', $this->var_name, true);
3. And edit view:
row in columns:
array(
'name'=>'var_name',
'value'=>'$data->table_name->related_column',
),
4. In model method rules() modify the rule used by search() and append the new attribute 'var_name':
// The following rule is used by search().
// Please remove those attributes that should not be searched.


你可能感兴趣的:(php,yii,relation,cgrid)