Detailed Explanation of page Method of ThinkPHP CURD Method

  • 2021-07-01 06:54:12
  • OfStack

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

We have already analyzed the situation of limit method for paging query, while page method is a more humane method for paging query. Let's take article list paging as an example. If limit method is used, we will query pages 1 and 2 (assuming that we output 10 pieces of data per page) as follows:


$Article = M('Article');
$Article->limit('0,10')->select(); //  Enquiry number 1 Page data 
$Article->limit('10,10')->select(); //  Enquiry number 2 Page data 

Although the limit parameters of each page can be automatically calculated by using the paging class Page in the extended class library, it is more laborious to write by yourself, and it is much simpler to write by page method, for example:


$Article = M('Article');
$Article->page('1,10')->select(); //  Enquiry number 1 Page data 
$Article->page('2,10')->select(); //  Enquiry number 2 Page data 

Obviously, with the page method you don't need to calculate the starting position of each paging data, but the page method automatically calculates it internally.

Since version 3.1, the page method also supports the writing of two parameters, such as:


$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 has only one value passed in, it indicates the page, while the limit method is used to set the number of displays per page, which means that the above writing is equivalent to:


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


Related articles: