Home > Backend Development > PHP Tutorial > Detailed explanation of page method of ThinkPHP CURD method_PHP tutorial

Detailed explanation of page method of ThinkPHP CURD method_PHP tutorial

WBOY
Release: 2016-07-13 10:24:47
Original
812 people have browsed it

The page method of ThinkPHP CURD method is also one of the model coherent operation methods. It is a humanized operation method completely born for paging query.
Usage

We have previously analyzed the use of the limit method for paging queries, and the page method is a more humane method for paging queries. Let us take paging in the article list as an example. If the limit method is used, We want to query the first and second pages (assuming we output 10 pieces of data per page) as follows:

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

Copy after login

Although the paging class Page in the extended class library can automatically calculate the limit parameter of each page, it is more laborious to write it yourself. It is much simpler if you use the page method to write it, for example:

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

Copy after login

Obviously, using the page method you do not need to calculate the starting position of each paged data, the page method will automatically calculate it internally.

Since version 3.1, the page method also supports the writing method of 2 parameters , for example:

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

Copy after login

and

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

Copy after login

Equivalent.

The page method can also be used in conjunction with the limit method , for example:

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

Copy after login

When the page method only has one value passed in, it indicates which page , and the limit method is used to set the number displayed on each page. That is to say, the above writing method is equivalent to:

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825325.htmlTechArticleThe page method of ThinkPHP CURD method is also one of the model coherent operation methods. It is a human nature born entirely for paging queries. ization operating methods. Usage We have analyzed previously about...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template