MoHaMmAd_K
(Mohammad K Aiu)
1
hallo everyone,
I have 3 models each one have relation with others, I want to configure the filter for that in GridView
this is the models:
serviceCenter Model:
public function relations()
{
return array(
'ownerData' => array(self::BELONGS_TO, 'Ownerdata', 'ownerData_id'),
}
OwnerData Model :
public function relations()
{
return array(
'provinceData' => array(self::BELONGS_TO, 'Provincedata', 'ProvinceData_id'),
);
}
and Provincedata Model has these columns
integer $id
string $provinceName
now what i have to do, is display the province name from ServiceCenter admin page with filter on it.
the grid view in admin page:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'my-grid',
'dataProvider'=>$servic->searchEX(),
'filter'=>$servic,
'columns'=>array(
'id',
array(
'name' => 'ownerData.name',
'filter' => CHtml::activeTextField($servic->searchName, 'name'),
),
array(
'name'=>'ownerData.ProvinceData_id',
),
....
Note: in the ownerData.name the filter work correctly
alirz23
(Alirz23)
2
MoHaMmAd_K
(Mohammad K Aiu)
3
thank you,
but this work with tow models and relation between its,
in my case I have
— Model A <–> Model B relation
— Model B <–> Model C relation
And in admin page (Model A) I need filtering the data which is at the (Model C)
softark
(Softark)
4
Hi MoHaMmAd_K, welcome to the forum.
It’s almost the same … just add the relation of “ownerData.proviceData” to “with”. 
$criteria = new CDbCriteria;
$criteria->with = array( 'ownerData', 'ownerData.provinceData' );
...
$criteria->compare( 'ownerData.name', $this->searchName, true );
$criteria->compare( 'provinceData.provinceName', $this->searchProviceName, true );
...
http://www.yiiframework.com/doc/guide/1.1/en/database.arr#performing-relational-query
m11
(m@ster)
5
I have the same problem
where you define "searchName" ?
because I will return this error:
PHP notice
Undefined variable: searchName
thanks
softark
(Softark)
6
@m@ster
Did you read the link that alirz23 has suggested?
le_top
(Ext Yiiframework Com)
8
I just released a behavior to help with this: Related Search Behavior