本文以實(shí)例代碼簡(jiǎn)述了yii實(shí)現(xiàn)分頁(yè)的方法,供學(xué)習(xí)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' => '首頁(yè)', 'lastPageLabel' => '末頁(yè)', 'prevPageLabel' => '上一頁(yè)', 'nextPageLabel' => '下一頁(yè)', 'pages' => $pages, 'maxButtonCount'=>13 ) ); ?>
新聞熱點(diǎn)
疑難解答