zoukankan      html  css  js  c++  java
  • ThinkPHP关于分页的使用

    在官方提供下载的实例文档中有一个关于分页的代码实例,原文如下:
    控制器IndexAction类
    <?php 
    class IndexAction extends Action{ 
        public function index() { 
                //自定义 
                $Form=M('Form'); 
                import("@.ORG.Page"); //导入分页类 
                $count = $Form->count();    //计算总数 
                $p = new Page ( $count, 5 ); 
                $list=$Form->limit($p->firstRow.','.$p->listRows)->order('id desc')->findAll(); 
                $p->setConfig('header','篇记录'); 
                $p->setConfig('prev',"<"); 
                $p->setConfig('next','>'); 
                $p->setConfig('first','<<'); 
                $p->setConfig('last','>>'); 
                $page = $p->show (); 
                $this->assign( "page", $page ); 
                $this->assign ( "list", $list ); 
                $this->display(); 
        } 
    
        public function Mypage(){ 
                //普通方式实现分页 
                $Form=M('Form'); 
                import("@.ORG.Page"); //导入分页类 
                $count = $Form->count();    //计算总数 
                $p = new Page ( $count, 5 ); 
                $list=$Form->limit($p->firstRow.','.$p->listRows)->order('id desc')->findAll(); 
                $page = $p->show (); 
                $this->assign ( "page", $page ); 
                $this->assign ( "list", $list ); 
                $this->display(); 
        } 
    } 
    ?> 


    其中的原理是 先导入分页类,然后计算总共的条数,最后用SQl的limit方法分段取数据。这个是最基本的一个分页方法。当然我们可以让这个操作变的完美一些。

    Meet so Meet. C plusplus I-PLUS....
  • 相关阅读:
    动态生成表格 (ng-zorro)
    单例服务
    模板变量 #
    HTML 5 系列
    关于tcp nagle算法
    netty 解包头包体的一点认知
    vargent Authentication failure.记录
    关于YII2.0配置的一点问题
    关于mysql b-tree索引的一点认知
    记vagrant nginx sendfile问题
  • 原文地址:https://www.cnblogs.com/iplus/p/4490055.html
Copyright © 2011-2022 走看看