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(); // 查询第二页数据
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(); // 查询第二页数据
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();
and
$Article->page('1,10')->select();
Equivalent.
The page method can also be used in conjunction with the limit method , for example:
$Article->limit(25)->page(3)->select();
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();