Code for CGridView:
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'id'=>'puzzle-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
'group.name',
array(
'name'=>'group_id',
'filter'=>CHtml::listData(PuzzleGroup::model()->findAll(),'id','name'),
),
'category.name',
'phrase',
array(
'name'=>'enabled',
'filter'=>array('Yes'=>'Yes','No'=>'No'),
),
array(
'class'=>'CButtonColumn',
),
),
));
//‘group.name’,
?>
Relations between the two tables:
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'tbHints' => array(self::HAS_MANY, 'TbHints', 'puzzle_id'),
'group' => array(self::BELONGS_TO, 'PuzzleGroup', 'group_id'),
'category' => array(self::BELONGS_TO, 'PuzzleCategory', 'category_id'),
);
}
Code for search function:
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id);
$criteria->compare('group_id',$this->group_id);
$criteria->compare('category_id',$this->category_id);
$criteria->compare('phrase',$this->phrase,true);
$criteria->compare('enabled',$this->enabled,true);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
For the above code can anyone please let me know how to create CGridView for Puzzle with dropdownlist filters containind puzzlegroup name from PuzzleGroup which is related to Puzzle with group_id.
Also i want to display PuzzleGroup name instead of id in the CGridView.