I want to change the CGridView text field to dropdown menu and change the numbers to categories name.
$model = new Products('search');
$model->unsetAttributes();
if(isset($_GET['Products'])){
$model->attributes=$_GET['Products'];
}
And in the view.
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'columns'=>array( 'code',
'category_id',
'quantity',
),
'filter'=>$model,
));
?>
Simply write in place of '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;
}
and $categoryArray
should be a array with keys as category id and value as category_name
$categoryArray = CHtml::listData(Category::model()->findAll() 'category_id', 'category_name')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.