我想将CGridView文本字段更改为下拉菜单,并将数字更改为类别名称。
$model = new Products('search');
$model->unsetAttributes();
if(isset($_GET['Products'])){
$model->attributes=$_GET['Products'];
}
在视图中。
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'columns'=>array( 'code',
'category_id',
'quantity',
),
'filter'=>$model,
));
?>
答案 0 :(得分:1)
只需代替&quot; category_id&#39;,
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;
}
和$categoryArray
应该是一个数组,其键为类别ID,值为category_name
$categoryArray = CHtml::listData(Category::model()->findAll() 'category_id', 'category_name')