[英]How to add dropdown menu in a CGridView Yii Framework?
我想將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,
));
?>
只需寫上“ 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')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.