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:
复制代码 代码如下:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Classification and Usage Analysis of JSP Comments JSP comments are divided into two types: single-line comments: ending with, only a single line of code can be commented. Multi-line comments: starting with /* and ending with */, you can comment multiple lines of code. Single-line comment example Multi-line comment example/**This is a multi-line comment*Can comment on multiple lines of code*/Usage of JSP comments JSP comments can be used to comment JSP code to make it easier to read

How to use the exit function in C language requires specific code examples. In C language, we often need to terminate the execution of the program early in the program, or exit the program under certain conditions. C language provides the exit() function to implement this function. This article will introduce the usage of exit() function and provide corresponding code examples. The exit() function is a standard library function in C language and is included in the header file. Its function is to terminate the execution of the program, and can take an integer

WPS is a commonly used office software suite, and the WPS table function is widely used for data processing and calculations. In the WPS table, there is a very useful function, the DATEDIF function, which is used to calculate the time difference between two dates. The DATEDIF function is the abbreviation of the English word DateDifference. Its syntax is as follows: DATEDIF(start_date,end_date,unit) where start_date represents the starting date.

How to use JavaScript to implement table paging function? With the development of the Internet, more and more websites use tables to display data. In some cases where the amount of data is large, the data needs to be displayed in pages to improve user experience. This article will introduce how to use JavaScript to implement table paging function and provide specific code examples. 1. HTML structure First, we need to prepare an HTML structure to host tables and paging buttons. We can use <tab

Introduction to Python functions: usage and examples of the abs function 1. Introduction to the usage of the abs function In Python, the abs function is a built-in function used to calculate the absolute value of a given value. It can accept a numeric argument and return the absolute value of that number. The basic syntax of the abs function is as follows: abs(x) where x is the numerical parameter to calculate the absolute value, which can be an integer or a floating point number. 2. Examples of abs function Below we will show the usage of abs function through some specific examples: Example 1: Calculation

Introduction to Python functions: Usage and examples of the isinstance function Python is a powerful programming language that provides many built-in functions to make programming more convenient and efficient. One of the very useful built-in functions is the isinstance() function. This article will introduce the usage and examples of the isinstance function and provide specific code examples. The isinstance() function is used to determine whether an object is an instance of a specified class or type. The syntax of this function is as follows

The ISNULL() function in MySQL is a function used to determine whether a specified expression or column is NULL. It returns a Boolean value, 1 if the expression is NULL, 0 otherwise. The ISNULL() function can be used in the SELECT statement or for conditional judgment in the WHERE clause. 1. The basic syntax of the ISNULL() function: ISNULL(expression) where expression is the expression to determine whether it is NULL or

MyBatis is an excellent persistence layer framework. It supports database operations based on XML and annotations. It is simple and easy to use. It also provides a rich plug-in mechanism. Among them, the paging plug-in is one of the more frequently used plug-ins. This article will delve into the principles of the MyBatis paging plug-in and illustrate it with specific code examples. 1. Paging plug-in principle MyBatis itself does not provide native paging function, but you can use plug-ins to implement paging queries. The principle of paging plug-in is mainly to intercept MyBatis
