PHP paging class usage (excerpted from yii framework)

WBOY
Release: 2016-07-25 08:52:42
Original
915 people have browsed it
  1. php;toolbar:false">/*public function actionReport()
  2. {
  3. $sql = "select * from {{goods}}";
  4. $criteria=new CDbCriteria();
  5. $result = Yii::app()->db->createCommand($sql)->query();
  6. $pages=new CPagination($result->rowCount);
  7. $pages->pageSize=2;
  8. $pages->applyLimit($criteria);
  9. $result=Yii::app()->db->createCommand($sql." LIMIT :offset,:limit");
  10. $result->bindValue(':offset', $pages->currentPage*$pages->pageSize);
  11. $result->bindValue(':limit', $pages->pageSize);
  12. $goodsInfo=$result->query();
  13. $this->render('index',array(
  14. 'goodsInfo'=>$goodsInfo,
  15. 'pages'=>$pages,
  16. ));
  17. }*/
复制代码
  1. foreach($goodsInfo as $v){
  2. ?>
  3. }
  4. ?>
  5. //分页widget代码:
  6. $this->widget('CLinkPager',array('pages'=>$pages));
  7. ?>
  8. 商品name 价格 更新时间
复制代码

方式二,使用自己的分页类来完成分页 1,控制器代码:

  1. public function actionIndex(){

  2. $goods_m=goods::model();

  3. //1.获得商品总的记录数目

  4. $cnt = $goods_m -> count();

  5. //2. 实例化分页类对象

  6. $page = new Page($cnt, 2);

  7. //3. 重新按照分页的样式拼装sql语句进行查询

  8. $sql = "select * from {{goods}} $page->limit";
  9. $goodsInfo = $goods_m -> findAllBySql($sql);

  10. //4. 获得分页页面列表(需要传递到视图模板里边显示)

  11. $pageList = $page->fpage();

  12. $this->renderPartial('index',array('goodsInfo'=>$goodsInfo,'pageList'=>$pageList));

  13. }

复制代码

2,视图代码:

  1. foreach($goodsInfo as $v){
  2. ?>
  3. }
  4. ?>
  5. echo $pageList;
  6. ?>
  7. 商品name price create_time
复制代码

分页类要放到能自动加载到的目录下就行;



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template