The page method is a user-friendly operation method completely created for paging query. This article mainly introduces the page method of the ThinkPHPCURD method, if you need it, you can refer to the page method of the ThinkPHP CURD method. it is also one of the methods for model coherent operations. it is a user-friendly operation method born completely for paging queries.
Usage
We have previously analyzed the use of the limit method for paging queries, while the page method is more user-friendly for paging queries. let's take the article list paging as an example, if the limit method is used, we need 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 (); // query the first page of Data $ Article-> limit ('10, 10')-> select (); // query the second page of data
Although the pagination Page in the extended class library can automatically calculate the limit parameter for each page, it is much harder to write it by yourself. if you use the Page method to write it, it is much easier, for example:
$ Article = M ('article'); $ Article-> page ('1, 10')-> select (); // query the first page of Data $ Article-> page ('2, 10')-> select (); // query the second page of data
Obviously,Using the page method, you do not need to calculate the start position of each page data. the page method automatically calculates the start position.
Since version 3.1, the page method also supports writing two parameters.For example:
$Article->page(1,10)->select();
And
$Article->page('1,10')->select();
Equivalent.
The page method can also be used with the limit method.For example:
$Article->limit(25)->page(3)->select();
WhenThe page method indicates the page number when only one value is input.The limit method is used to set the number of entries displayed on each page, that is, the preceding statement is equivalent:
$Article->page('3,25')->select();