如何在CGridView Yii框架中添加下拉菜单?

I want to change the CGridView text field to dropdown menu and change the numbers to categories name.

category grid view

$model = new Products('search');
        $model->unsetAttributes();  
        if(isset($_GET['Products'])){
           $model->attributes=$_GET['Products'];
        }

And in the view.

<?php
       $this->widget('zii.widgets.grid.CGridView', array(
       'dataProvider'=>$model->search(),                               
       'columns'=>array(                                                                                                                                                       'code',
            'category_id',
            'quantity',
            ),
           'filter'=>$model,
        ));
    ?>

Simply write in place of 'category_id',

array(
           // 'name' => 'category_id',
             'header'=>'Category Name',
            'value' => '$data->categoryname($data->category_id)',
            'filter' => $categoryArray
        ),


categoryname() should be written in your `Product Model`.  



  Product Model
public function categoryname($category_id){
//fetch your category name with this category id and return it

return categoryName;
}

and $categoryArray should be a array with keys as category id and value as category_name

$categoryArray = CHtml::listData(Category::model()->findAll() 'category_id', 'category_name')