2016-07-09 98 views
0

我想要將CGridView文本字段更改爲dromdown菜單並將數字更改爲類別名稱。如何在CGridView Yii Framwork中添加下拉菜單?

category grid view

$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, 
     )); 
    ?> 

回答

1

到位 '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') 
+0

它的作品!坦克。 – Hamid