Home php教程 php手册 ThinkPHP CURD方法之page方法详解

ThinkPHP CURD方法之page方法详解

Jun 06, 2016 pm 08:21 PM
page thinkphp

page方法是完全为分页查询而诞生的一个人性化操作方法这篇文章主要介绍了ThinkPHP CURD方法的page方法,需要的朋友可以参考下

ThinkPHP CURD方法的page方法也是模型连贯操作方法之一,是完全为分页查询而诞生的一个人性化操作方法。
用法

我们在前面已经分析了关于limit方法用于分页查询的情况,而page方法则是更人性化的进行分页查询的方法,我们还是以文章列表分页为例来说,,如果使用limit方法,我们要查询第一页和第二页(假设我们每页输出10条数据)写法如下:

$Article = M('Article'); $Article->limit('0,10')->select(); // 查询第一页数据 $Article->limit('10,10')->select(); // 查询第二页数据

虽然利用扩展类库中的分页类Page可以自动计算出每个分页的limit参数,但是如果要自己写就比较费力了,如果用page方法来写则简单多了,例如:

$Article = M('Article'); $Article->page('1,10')->select(); // 查询第一页数据 $Article->page('2,10')->select(); // 查询第二页数据

显而易见的是,使用page方法你不需要计算每个分页数据的起始位置,page方法内部会自动计算。

自3.1版本以后,page方法也支持2个参数的写法,例如:

$Article->page(1,10)->select();

$Article->page('1,10')->select();

等效。

page方法还可以和limit方法配合使用,例如:

$Article->limit(25)->page(3)->select();

当page方法只有一个值传入的时候,表示第几页,而limit方法则用于设置每页显示的数量,也就是说上面的写法等同于:

$Article->page('3,25')->select();

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

How to run thinkphp project

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

There are several versions of thinkphp

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

How to run thinkphp

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

How to install thinkphp

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Which one is better, laravel or thinkphp?

Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Nov 22, 2023 pm 12:01 PM

Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks

How is the performance of thinkphp? How is the performance of thinkphp? Apr 09, 2024 pm 05:24 PM

How is the performance of thinkphp?

ThinkPHP6 backend management system development: realizing backend functions ThinkPHP6 backend management system development: realizing backend functions Aug 27, 2023 am 11:55 AM

ThinkPHP6 backend management system development: realizing backend functions

See all articles