我想将 CGridView 文本字段更改为下拉菜单,并将数字更改为类别名称。
$model = new Products('search');
$model->unsetAttributes();
if(isset($_GET['Products'])){
$model->attributes=$_GET['Products'];
}
并且在 View 中。
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'columns'=>array( 'code',
'category_id',
'quantity',
),
'filter'=>$model,
));
?>
最佳答案
只需写入“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;
}
和 $categoryArray
应该是一个数组,其中键为类别 id,值为category_name
$categoryArray = CHtml::listData(Category::model()->findAll() 'category_id', 'category_name')
关于php - 如何在 CGridView Yii 框架中添加下拉菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38286518/