本文实例讲述了Yii实现简单分页的方法。分享给大家供大家参考,具体如下:
yii分页方法
1
2
3
4
5
6
7
8
9
10
11
12
13
|
function actionPage(){ $criteria = new CDbCriteria(); $count =Archives::model()-> count ( $criteria ); $pages = new CPagination( $count ); // results per page $pages ->pageSize=10; $pages ->applyLimit( $criteria ); $models =Archives::model()->findAll( $criteria ); $this ->render( 'Archives' , array ( 'models' => $models , 'pages' => $pages )); } |
view视图的方法
1
2
3
4
5
6
7
8
9
10
11
12
|
<ul> <?php foreach ( $models as $model ): ?> <li><?php echo $model ->title;?></li> <?php endforeach ; ?> </ul> <?php $this ->widget( 'CLinkPager' , array ( 'pages' => $pages , 'header' => '' , 'prevPageLabel' => '上一页' , 'nextPageLabel' => '下一页' , 'cssFile' => 'css/cc/css.css' , )) ?> |
希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。