zoukankan      html  css  js  c++  java
  • Yii 自带的分页实例

    yii自带的分页很好用,简单的几行代码就能把分页搞出来,唯一恼火的是只能写在controller中,所以有时候controller中的方法有点臃肿。废话少说,上代码上图。

    一、代码实例:

    1、控制器中的代码(红色的代码是分页必须的

            $c = new CDbCriteria();
            $c ->order = 'tid';  
            if($status){
                $c->addCondition('status='.$status); //根据状态查询
            }
            if($searchtxt){
                $c->addSearchCondition('topic_title', $searchtxt); //根据标题查询
            }
            $c->addCondition('end_time<'.'"'.date('Y-m-d H:i:s',time()).'"'); //过期专题
            
            $count = SpecialTopic::model()->count($c);  //查询到的总数目

            $pager = new CPagination($count);   
            $pager->pageSize=8;     //页面条数
            $pager->applyLimit($c);
            $topicModel = SpecialTopic::model()->findAll($c);

            
            //渲染视图
            Yii::app()->getController()->render('specialtopic/introducetopics',array(
                'topicModel'=>$topicModel,
                'pages' => $pager,
                    ));

    2、视图中的代码

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


    你坚持下来了,这就是你的资本!
  • 相关阅读:
    Wooden Sticks(hdu1051)
    Leftmost Digit(hdu1060)(数学题)
    Sum of Remainders(数学题)
    Brain Network (medium)(DFS)
    Brain Network (easy)(并查集水题)
    Collective Mindsets (medium) (逻辑题)
    Collective Mindsets (easy)(逻辑题)
    RMQ with Shifts(线段树)
    Throwing Dice(概率dp)
    圆桌会议
  • 原文地址:https://www.cnblogs.com/jamespan23/p/5349632.html
Copyright © 2011-2022 走看看