YII分页方法(控制器与视图分页)
时间:2021-07-01 10:21:17
帮助过:16人阅读
- 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));
- } // bbs.it-home.org
2,视图部分代码:
- foreach($list as $o)
- {
- echo $o->username.'
'; - echo $o->id.'
'; - }
- $this->widget('CLinkPager',array(
- 'header'=>'',
- 'firstPageLabel' => '首页',
- 'lastPageLabel' => '末页',
- 'prevPageLabel' => '上一页',
- 'nextPageLabel' => '下一页',
- 'pages' => $pages,
- 'maxButtonCount'=>13
- )
- );
|