zoukankan      html  css  js  c++  java
  • Yii 分页方法总结

    在 Controller中如下代码:

    public function actionIndex()    
        {    
            $criteria = new CDbCriteria();    
            $criteria->order = 'createtime desc';        
            $count = Article::model()->count($criteria);    
                
            $pager = new CPagination($count);    
            $pager->pageSize = 10;             
            $pager->applyLimit($criteria);    
        
            $artList = Article::model()->findAll($criteria);    
            $this->render('index',array('pages'=>$pager,'list'=>$artList));    
        }  
    

     在视图中代码如下:

    <div id="pager">    
        <?php    
        
        $this->widget('CLinkPager',array(    
            'header'=>'',    
            'firstPageLabel' => '首页',    
            'lastPageLabel' => '末页',    
            'prevPageLabel' => '上一页',    
            'nextPageLabel' => '下一页',    
            'pages' => $pages,    
            'maxButtonCount'=>13    
            )    
        );    
        ?>    
        </div> 
    

     一般写法:

    $criteria = new CDbCriteria;    
    $count = DnOnline::model()->count($criteria);    
        
    $pages = new CPagination($count);                   
    $pages->pageSize = 5;    
    $pages->applylimit($criteria);    
        
    $model = DnOnline::model()->findAll($criteria); 
    

     CDB写法:

    $criteria = new CDbCriteria;    
        $sql = "SELECT * FROM USER";    
        $model= Yii::app()->db->createCommand($sql)->queryAll();    
        $pages = new CPagination(count($model));                   
        $pages->pageSize = 4;    
        $pages->applylimit($criteria);    
        
        $model=Yii::app()->db->createCommand($sql." LIMIT :offset,:limit");    
        $model->bindValue(':offset', $pages->currentPage*$pages->pageSize);    
        $model->bindValue(':limit', $pages->pageSize);    
        $model=$model->queryAll();   
    
        $criteria=new CDbCriteria();    
                    $result = Yii::app()->db->createCommand($sql_do)->query();    
                   $pages=new CPagination($result->rowCount);    
                  $pages->pageSize=2;    
                    $pages->applyLimit($criteria);    
                  $result=Yii::app()->db->createCommand($sql_do." LIMIT 2");    
                   $result->bindValue(':offset', $pages->currentPage*$pages->pageSize);    
                 $result->bindValue(':limit', $pages->pageSize);    
                 $list=$result->query();   
    
  • 相关阅读:
    什么是回归测试?
    单元测试、集成测试、系统测试的侧重点是什么?
    一个测试工程师应具备那些素质?
    你所了解的的软件测试类型都有哪些,简单介绍一下。
    Python
    爬虫-urllib3模块的使用
    爬图片(附,源码)
    MySQL存储引擎:MyISAM和InnoDB的区别
    员工管理系统
    MySQL锁(二)表锁:为什么给小表加字段会导致整个库挂掉?
  • 原文地址:https://www.cnblogs.com/moleng/p/2958038.html
Copyright © 2011-2022 走看看