Class CPagination
CPagination represents information relevant to pagination.
When data needs to be rendered in multiple pages, we can use CPagination to represent information such as getItemCount total item count, getPageSize page size, getCurrentPage current page, etc. These information can be passed to CBasePager pagers to render pagination buttons or links.
Example:
Controller action:
function actionIndex(){ $criteria=new CDbCriteria(); $count=Article::model()->count($criteria); $pages=new CPagination($count); // results per page $pages->pageSize=10; $pages->applyLimit($criteria); $models=Article::model()->findAll($criteria); $this->render('index', array( 'models' => $models, 'pages' => $pages )); }
View:
<?php foreach($models as $model): ?> // display a model <?php endforeach; ?> // display pagination <?php $this->widget('CLinkPager', array( 'pages' => $pages, )) ?>
- CComponent
- CPagination
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/web/CPagination.php
public
|
|
public
integer
|
|
public
|
|
public
integer
|
|
public
|
|
public
integer
|
|
public
integer
|
|
public
|
|
public
string
|
#
createPageUrl(
Creates the URL suitable for pagination. This method is mainly called by pagers when creating URLs used to perform pagination. The default implementation is to call the controller's createUrl method with the page information. You may override this method if your URL scheme is not the same as the one supported by the controller's createUrl method. |
public
|
|
public
integer
|
|
public
integer
|
integer |
DEFAULT_PAGE_SIZE
|
10 |
#
The default page size. |
public
string
|
$pageVar | 'page' |
#
name of the GET variable storing the current page index. Defaults to 'page'. |
public
string
|
$route | '' |
#
the route (controller ID and action ID) for displaying the paged contents. Defaults to empty string, meaning using the current route. |
public
array
|
$params |
|
#
of parameters (name=>value) that should be used instead of GET when generating pagination URLs. Defaults to null, meaning using the currently available GET parameters. |
public
boolean
|
$validateCurrentPage | true |
#
whether to ensure currentPage is returning a valid page number. When this property is true, the value returned by currentPage will always be between 0 and (pageCount-1). Because pageCount relies on the correct value of itemCount, it means you must have knowledge about the total number of data items when you want to access currentPage. This is fine for SQL-based queries, but may not be feasible for other kinds of queries (e.g. MongoDB). In those cases, you may set this property to be false to skip the validation (you may need to validate yourself then). Defaults to true. |
public
integer
|
$pageSize |
#
Number of items in each page. Defaults to 10. |
public
integer
|
$itemCount |
#
Total number of items. Defaults to 0. |
public
integer
|
$pageCount |
#
Number of pages. |
public
integer
|
$currentPage |
#
The zero-based index of the current page. Defaults to 0. |
public
integer
|
$offset |
#
The offset of the data. This may be used to set the OFFSET value for a SQL statement for fetching the current page of data. |
public
integer
|
$limit |
#
The limit of the data. This may be used to set the LIMIT value for a SQL statement for fetching the current page of data. This returns the same value as pageSize. |