thinkphp implementing an array paging _php tutorial

Source: Internet
Author: User

Paging is implemented under the framework of thinkphp. The company's website is based on the thinkphp framework, has been heard thinkphp name, finally have the opportunity to combat. Thinkphp is an MVC architecture, and MVC is no stranger to any iters, model-View-controller. He separates the logic and the data, with a lot less tedious process. In fact, in the official information has been described in detail how to paging, Portal: Http://document.thinkphp.cn/manual_3_2.html#data_page

However, it does not apply to the data has been removed from the DB, and converted to an array of cases, I contacted PHP uttered 2 months, contact thinkphp 3 weeks. Before spending a lot of time on official documents, to be familiar with thinkphp. It's ax. The official documentation is described here as a comparison:
(Only the first method on the document): using the Page class and the Limit method, the code is as follows:

= M (' User ');=->where (' Status=1 ')-> ();  =  \think\page (,25);   = ->show ();  = ->where (' Status=1 ' ->order (' Create_time ')->limit (->firstrow. ', '.  ->listrows)->->assign (' list ', );  ->assign (' page ', ); ->display ();               /span>               

< span="">

< span="">

PHP's own function array_slice () is used. Definition here: http://www.php.net/manual/en/function.array-slice.php
is actually the array version of the Limit method. Well, the tools have been found, and the implementation is easy. Directly on the code:

  =  = ->getnodelists (-> =  ([' data ' 
                
                  =  Page (,10
                    
                      =  ([' data '), Span $p span>->firstrow,-> = ->< span Show (); Span>->assign (' page ', 
                              
                               ->assign (' Nodes ', 
                                 
                                  ->   
                                  
                              
                    
                 

< span="">

The 3rd line Getnodelists method extracts the data from the database and assigns it to the array nodelist.
Line 5th Count counts the number of elements in the array.
6th behavior the page class passed in parameters.
The Array_slice function in line 7th replaces the limit method. Same principle.
The 9th line assigns a value to the template using the Assign method. Definition here: http://document.thinkphp.cn/manual_3_2.html#assign
The 10th line is the same.

The code in view:

= "Page-list" >< span="">< span="">< span="">

< span="">

< span="">< span="">< span="">< span="">< span="">< span="">' Header ' = ' total%total_row% ', ' prev ' = ' prev ', ' next ' = ' next ', ' first ' = ' page ', ' last ' = ' ...% Total_page% ', ' theme ' = '%first%%up_page%%link_page%%down_page% ',

< span="">

http://www.bkjia.com/PHPjc/754073.html www.bkjia.com true http://www.bkjia.com/PHPjc/754073.html techarticle paging is implemented under the framework of thinkphp. The company's website is based on the thinkphp framework, has been heard thinkphp name, finally have the opportunity to combat. Thinkphp is the MVC architecture, MVC for any ITER ...

  • 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.