Data pagination for version 3.2

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn about the absence of data classification instructions in the official manual of version 3.2. I tried to debug it today and it basically works, for beginners.
First Import ('org. Util. page'); // import the paging classThis statement is no longer needed because the Page Template of version 3.2 is changed to the Think class library.

In general, the Code is not much different from version 3.1 (this is the case in Visual Testing). Let's get my code:
$ Article = M ('Article'); // instantiate a Data Object
$ Count = $ Article-> count (); // The total number of records that meet the query requirements. $ map indicates the query conditions.
$ Page = new \ Think \ Page ($ count, 15); // instantiate the total number of records passed in by the paging class (this is modified according to @ 979137, which is recommended very well !)
$ Show = $ Page-> show (); // display the output by Page
// Query paging data
$ Orderby ['id'] = 'desc ';
$ List = $ Article-> order ($ orderby)-> limit ($ Page-> firstRow. ','. $ Page-> listRows)-> select ();
$ This-> assign ('LIST', $ list); // assign a value to a dataset
$ This-> assign ('page', $ show); // value-assigned paging output
$ This-> display (); // output Template
If you change the model in M. Then, the most important thing to note is, $Page = new \Think\Page($count, 15);This statement, because I have read the code of the Page class, it does not seem to assign an initial value to the number of entries to be displayed on each Page. If you do not input the second parameter "15 ", the Page class does not know the number of entries to be displayed on each Page, so it will not be able to display paging data. Pay attention to this. I just tested it and it can basically be used. If you have any questions in the future, I will try again. Please give me more advice!

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.