Home > PHP Framework > ThinkPHP > body text

What is the page method of thinkphp?

WBOY
Release: 2022-02-25 11:58:49
Original
3073 people have browsed it

In thinkphp, the page method is one of the model coherent operation methods. It is a humanized operation method born for paging queries. Using this method does not need to calculate the starting position of each paging data. The purpose of this method is It will be automatically calculated internally, and the syntax is "$Article->page(1,10)->select();".

What is the page method of thinkphp?

The operating environment of this article: Windows 10 system, ThinkPHP version 5, Dell G3 computer.

What is the page method of thinkphp?

The page method is one of the coherent operation methods of the model. It is a humanized operation method that was completely born for paging query.

Usage

We have already learned about the use of the limit method for paging queries, and the page method is a more humane method for paging queries. For example, taking article list paging as an example, if we use the limit method, we need to query the first and second pages (assuming we output 10 pieces of data per page). The writing is as follows:

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

Although using the extension class The paging class Page in the library can automatically calculate the limit parameter of each page, but 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

The obvious thing is , 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.

After version 3.1, the page method also supports the writing of two parameters, for example:

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

and

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

are 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 each page. The displayed quantity, that is to say, the above writing method is equivalent to:

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

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the page method of thinkphp?. For more information, please follow other related articles on the PHP Chinese website!

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