本文以實例代碼簡述了yii實現分頁的方法,供學習yii的朋友參考,具體代碼如下:
1.控制器部分代碼:
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.視圖部分代碼:
<?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 ) ); ?>