search
Homephp教程php手册Yii把CGridView文本框换成下拉框的方法,yiicgridview

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

本文实例讲述了Yii把CGridView文本框换成下拉框的方法。分享给大家供大家参考。具体实现方法如下:

使用yii的朋友都知道Yii中的CGridView默认显示提文本框了,那么我们要怎么把它转换成下拉框呢?本文就此分析一下解决方法。

默认情况下CGridView会生成一个文本框,但是这并不友好,用户往往希望知道有什么可选的,特别是数据库里存的是数字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下拉框可以这么写:

复制代码 代码如下:

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

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

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.