本文以实例代码简述了yii实现分页的方法,供学习yii的朋友参考,具体代码如下:
1.控制器部分代码:
1
2
3
4
5
6
7
8
9
10
11
|
public function actionTest() { $criteria = new CDbCriteria; $criteria ->order= 'id DESC' ; $count =User::model()-> count ( $criteria ); $pager = new CPagination( $count ); $pager ->pageSize=10; $pager ->applyLimit( $criteria ); $userList =User::model()->findAll( $criteria ); $this ->render( 'test' , array ( 'list' => $userList , 'pages' => $pager )); } |
2.视图部分代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<?php foreach ( $list as $o ) { echo $o ->username. '<br/>' ; echo $o ->id. '<br/>' ; } $this ->widget( 'CLinkPager' , array ( 'header' => '' , 'firstPageLabel' => '首页' , 'lastPageLabel' => '末页' , 'prevPageLabel' => '上一页' , 'nextPageLabel' => '下一页' , 'pages' => $pages , 'maxButtonCount' =>13 ) ); ?> |