I found a solution for this, but I’m not sure if it’s optimal. Anyway, this is what I do:
Button model:
public $panelId;
public function afterFind()
{
parent::afterFind();
if ($this->scenario === 'search' && !is_null($this->layer)) {
$this->panelId = $this->layer->panelId;
}
}
public function search()
{
$criteria = $this->getSearchCriteria();
$criteria->compare('id', $this->id);
$criteria->compare('t.name', $this->name, true);
$criteria->compare('panelId', $this->panelId);
$criteria->with = array('layer'=>array('with'=>'panel'));
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => 15,
),
));
}
View:
<?php $this->widget('zii.widgets.grid.CGridView',array(
'id'=>'button-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'panelId',
'value'=>'!empty($data->layer) ? CHtml::encode($data->layer->panel->name) : ""',
'filter' => CHtml::dropDownList('Button[panelId]', $model->panelId, CHtml::listData(Panel::model()->findAll(array('order'=>'name')), 'id', 'name'), array('empty' => 'Choose panel...')),
),
array(
'name'=>'layerId',
'value'=>'!is_null($data->layerId) ? CHtml::encode($data->layer->name) : ""',
'filter' => CHtml::dropDownList('Button[layerId]', $model->layerId, CHtml::listData(Layer::model()->findAll(array('order'=>'name')), 'id', 'name'), array('empty' => 'Choose layer...')),
),
'name',
array(
'class' => 'CButtonColumn',
),
),
)); ?>
Any thouhts for improving this are welcome 