Yii把CGridView文本框换成下拉框的方法

选取yii的相恋的人都知道Yii中的CGridView暗中同意呈现提文本框了,那么大家要怎么把它调换到下拉框呢?本文就此分析一下化解措施。

生成type下拉框能够这么写:

生成type下拉框能够这么写:
复制代码 代码如下:’type’=>array(
    ‘name’ => ‘type’,
    ‘filter’=>$model->getTypeOptions(),
),

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

愿意本文所述对大家基于Yii框架的PHP程序设计有着援救。

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

暗中认可情状下CGridView会生成三个文本框,但是这并不协和,客户往往愿意知晓有哪些可选的,特别是数据Curry存的是数字id的时候,大家愿意将数字转变为可读的文书,这个时候只须求校正一下表头的”filter”属性就行了,比方:
复制代码 代码如下:
$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”))’,
        ),
    ),
));

 代码如下

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

 代码如下

正文实例呈报了Yii把CGridView文本框换来下拉框的方法。分享给我们供我们参考。具体落实格局如下:

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

默许意况下CGridView会生成叁个文本框,不过这并不和睦,顾客往往愿意知道有怎么着可选的,极其是数据库里存的是数字id的时候,我们希望将数字调换为可读的公文,这个时候只必要校订一下表头的”filter”属性就能够了,比如:

发表评论

电子邮件地址不会被公开。 必填项已用*标注