2016-07-09 6 views
0

Ich möchte das CGridView-Textfeld in dromdown-Menü ändern und die Nummern in Kategorien ändern.Wie füge ich ein Dropdown-Menü in einem CGridView Yii Framwork hinzu?

category grid view

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

Und in der Ansicht.

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

Antwort

1

einfach anstelle von 'category_id' schreiben,

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; 
} 

und $categoryArray sollte

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

es funktioniert ein Array mit Schlüssel als Kategorie-ID und den Wert als category_name sein! Panzer. – Hamid