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....
  • 相关阅读:
    通用二进制格式安装、编译安装过程(以mysql为例)
    linux:网络
    深圳:软通-运维
    深圳:软通-python
    linux:用户管理
    linux:vim
    深圳:卡莱特-售前/售后服务
    linux:基本指令
    linux:安装
    电脑:磁盘扩容
  • 原文地址:https://www.cnblogs.com/iplus/p/4490055.html
Copyright © 2011-2022 走看看