One page is the model methods consistent method of operation

page method is also one consistent method of operation model is a user-friendly method of operation is entirely paging query born.

We have already learned about the situation with regard to the method used to limit the query page, and page pagination method is a method of inquiry be more humane, for example, or in the article list page, for example, if the use limit approach, we want to query The first and second pages (we assume 10 per output data) is written as follows:

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

While using the extended class library paging Page class can automatically calculate the limit parameters for each page, but if you want to write your own is more laborious, if the page is a simple way to write more, for example:

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

Be apparent that, you do not need to use the page method calculates the starting position for each page of data, the method automatically calculates the internal page.

After version 3.1, page supports two methods of writing parameters, such as:

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

with

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

Equivalent.

The method also can be page limit with a method, for example:

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

When the page is only one value of time passed, represent the first few pages, and limit the number of methods is used to set the per page, that is written above is equivalent to:

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

Guess you like

Origin www.cnblogs.com/furuihua/p/11804312.html