3.2版本的官方手册上一直没有数据分类的说明,我今天试着调试了一下,基本行得通,给一些初学者看看。
首先import('ORG.Util.Page');// 导入分页类
这个语句不用了,因为3.2版本的Page模板换到了Think类库里面。
然后大体上代码与3.1版本的区别不大(目测是这样),下面我给弄一下我的代码:
$Article = M('Article'); // 实例化Data数据对象<br>
$count = $Article->count();// 查询满足要求的总记录数 $map表示查询条件<br>
$Page = new \Think\Page($count, 15);// 实例化分页类 传入总记录数(这是根据@979137的意见修改的,这个建议非常好!)<br>
$show = $Page->show();// 分页显示输出<br>
// 进行分页数据查询<br>
$orderby['id']='desc';<br>
$list = $Article->order($orderby)->limit($Page->firstRow.','.$Page->listRows)->select();<br>
$this->assign('list',$list);// 赋值数据集<br>
$this->assign('page',$show);// 赋值分页输出<br>
$this->display(); // 输出模板
你如果使用的时候,把M()里面的模型换了。然后最值得注意的一点就是,$Page = new \Think\Page($count, 15);
这个语句,因为我看了一下Page类的代码,它好像没有给每页要显示的条数赋初始值,你如果不传入第二个参数"15",那么Page类就不知道你每页要显示的条数,所以就到时候就无法显示分页数据。这个一定要注意一下。我刚测试了一下,基本上能用,后期如果还有什么问题,我再完善一下。也请高手多多指教!
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
