This article briefly describes the method of paging in Yii with example code for reference by friends who are learning Yii. The specific code is as follows:
1. Controller part code:
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. View part code:
<?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 ) ); ?>
For more articles related to how YII implements paging, please pay attention to the PHP Chinese website!