search
Homephp教程php手册Yii分页用法实例详解

这篇文章主要介绍了Yii分页用法,以实例形式详细分析了比较常见的几种分页方法及其应用特点,非常具有实用价值,需要的朋友可以参考下

下面我总结了在Yii常用的一些yii分页方式与实例代码,这里有普通分页与ajax实现分页,希望此文章对大家会有所帮助。

第一种:CListView分页  针对对象形式的数据分页

Controller:

复制代码 代码如下:

public function actionAjax() {
        $criteria = new CDbCriteria();
        //$criteria->order = 'news_id DESC';
        $criteria->condition = 'user_id = 1';
 
        $dataProvider = new CActiveDataProvider('News', array(
                    'pagination' => array(
                        'pageSize' => Yii::app()->params['pagesize'],
                        'pageVar' => Yii::app()->params['pagevar'],
                    ),
                    'criteria' => $criteria,
                ));
 
 
        $this->render('view', array(
            'dataProvider' => $dataProvider,
        ));
}


View:

复制代码 代码如下:

$this->widget('zii.widgets.CListView', array(
    'dataProvider' => $dataProvider, //数据
    'itemView' => '_view', //显示的模版
    'id' => Yii::app()->controller->id,
    'itemsTagName' => 'ul',
    'ajaxVar' => '', //默认为page或ajax 去掉后url更简洁
    'htmlOptions' => array('class' => Yii::app()->controller->id),
    'loadingCssClass' => 'loading', //默认为list-view-loading
    //'template' => '{summary}{sorter}{items}{pager}',//显示的顺序
    //'ajaxUpdate' => false, //是否ajax分页  false或分页显示的容器id
    //'beforeAjaxUpdate' => 'before_ajax_update',   //回调函数 在common.js里完成
    //'afterAjaxUpdate' => 'after_ajax_update',  
    'emptyText' => '


    暂无数据!

', //无数据时显示内容
                    'pagerCssClass' => 'pagination', //分页的class
                    'pager' => array(
                        'selectedPageCssClass' => 'active', //当前页的class
                        'hiddenPageCssClass' => 'disabled', //禁用页的class
                        'header' => '', //分页前显示的内容
                        'maxButtonCount' => 10, //显示分页数量
                        'htmlOptions' => array('class' => ''),
                        'firstPageLabel' => '首页',
                        'nextPageLabel' => '下一页',
                        'prevPageLabel' => '上一页',
                        'lastPageLabel' => '末页',
                    ),
                ));
?>

第二种:CLinkPager  针对数组形式的数据分页

Controller:

复制代码 代码如下:

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

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

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.