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:
-
How to pass in the related model (“parent”) in the filter, so admins may search in the textfield that’s rendered
-
How to allow admins to use the Advanced Search for the parent
My view:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'classes-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'pager'=>array('class'=>'CListPager'),
'columns'=>array(
'id',
//'title',
'parent.title:text:Parent Title',
'price:text:Price',
),
)); ?>
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(
'parent'=>array(
'select'=>'title'
)
);
//$criteria->addSearchCondition('parent.title',$this->parent->title);
$criteria->compare('id',$this->id,true);
//$criteria->compare('parentTitle',$this->parentTitle,true);
$criteria->compare('price',$this->price,true);
return new CActiveDataProvider(get_class($this), array('criteria'=>$criteria,
'pagination'=>array('pageSize'=>50),
));
}
I’ve even played around with declaring:
public $parentTitle=’’;
as a variable of my Child model class.
Ideas?