当前位置:Gxlcms > PHP教程 > YII分页方法(控制器与视图分页)

YII分页方法(控制器与视图分页)

时间:2021-07-01 10:21:17 帮助过:16人阅读

  1. public function actionTest()
  2. {
  3. $criteria=new CDbCriteria;
  4. $criteria->order='id DESC';
  5. $count=User::model()->count($criteria);
  6. $pager=new CPagination($count);
  7. $pager->pageSize=10;
  8. $pager->applyLimit($criteria);
  9. $userList=User::model()->findAll($criteria);
  10. $this->render('test',array('list'=>$userList,'pages'=>$pager));
  11. } // bbs.it-home.org

2,视图部分代码:

  1. foreach($list as $o)
  2. {
  3. echo $o->username.'
    ';
  4. echo $o->id.'
    ';
  5. }
  6. $this->widget('CLinkPager',array(
  7. 'header'=>'',
  8. 'firstPageLabel' => '首页',
  9. 'lastPageLabel' => '末页',
  10. 'prevPageLabel' => '上一页',
  11. 'nextPageLabel' => '下一页',
  12. 'pages' => $pages,
  13. 'maxButtonCount'=>13
  14. )
  15. );

人气教程排行