Home  >  Article  >  Backend Development  >  How to replace the CGridView text box with a drop-down box in Yii, yiicgridview_PHP tutorial

How to replace the CGridView text box with a drop-down box in Yii, yiicgridview_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:12:21696browse

Yii method to replace the CGridView text box with a drop-down box, yiicgridview

The example in this article describes how Yii replaces the CGridView text box with a drop-down box. Share it with everyone for your reference. The specific implementation method is as follows:

Friends who use Yii know that the CGridView in Yii displays a text box by default, so how do we convert it into a drop-down box? This article will analyze the solution.

By default, CGridView will generate a text box, but this is not user-friendly. Users often want to know what options are available, especially when the database stores numeric IDs. We want to convert the numbers into readable ones. Text, then you only need to modify the "filter" attribute of the table header, such as:

Copy code The code is as follows:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'business-grid',
'dataProvider'=>$dataProvider,
'filter'=> Business::model(),
'columns'=>array(
         'business_id',
         'name',
         'package_id'=> array(
              'name' => 'package_id',
              'value' => '$data->package->package_title',
'filter'=> CHtml::listData(Packages::model()->findAll(array('order'=>'package_title')), 'package_id', 'package_title')
),
         'user_id'=>array(
             'name' => 'user_id',
              'value' => '$data->user->name',
'filter'=> CHtml::listData(Users::model()->findAll(array('order'=>'firstname')), 'id', 'name')
),
         'categories' => array(
             'name' => 'categories',
              'value' => '$data->returnAllCategories(", ",false);',
'filter'=> CHtml::listData(Categories::model()->findAll(array('order'=>'category')), 'cat_id', 'category')
),
          'keywords' => array(
               'header' => 'Keywords',
              'value' => '$data->returnAllKeywords(", ",false);',
),
         'links'=>array(
             'header'=>'Manage',
             'type'=>'raw',
'value'=>'CHtml::link(CHtml::image(Yii::app()->request->baseUrl."/images/admin/approve.png","Approve"), array( "approve","id"=>$data->business_id,"item"=>"business"),array("class"=>"approve-link","title"=>"Approve Business"))." ".
CHtml::link(CHtml::image(Yii::app()->request->baseUrl."/images/admin/reject.png","Reject"), array("reject","id" =>$data->business_id,"item"=>"business"),array("class"=>"reject-link","title"=>"Reject Business"))',
),
),
));

The generated type drop-down box can be written as follows:

Copy code The code is as follows:
'type'=>array(
'name' => 'type',
'filter'=>$model->getTypeOptions(),
),

'type'=>array(
'name' => 'type',
'filter'=>$model->getTypeOptions(),
),

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/920977.htmlTechArticleYii's method of replacing the CGridView text box with a drop-down box, yiicgridview This article explains how to replace the CGridView text box with Yii's drop-down box method. Share it with everyone for your reference. Specific implementation method...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn