ThinkPHP关于分页的使用

来源:互联网 发布:java 未来 知乎 编辑:程序博客网 时间:2024/05/16 11:50
在官方提供下载的实例文档中有一个关于分页的代码实例,原文如下:
控制器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方法分段取数据。这个是最基本的一个分页方法。当然我们可以让这个操作变的完美一些。

原创粉丝点击