Thinkphp3.2.3 paging code sharing _ php instance

Source: Internet
Author: User
This article mainly introduces thinkphp3.2.3 paging code, which is very practical. if you are interested, you can refer to the implementation effects of thinkphp paging in two call methods, A method to call functions in common functions (refer to the http://www.cnblogs.com/tianguook/p/4326613.html), a method to write paging in the model


1. write in the public function Application/Common/function. php:

Function getpage ($ count, $ pagesize = 10) {$ page = new Think \ Page ($ count, $ pagesize); $ page-> setConfig ('header ','
  • Total% TOTAL_ROW %Records% NOW_PAGE %/% TOTAL_PAGE %Page
  • '); $ Page-> setConfig ('prev', 'Previous page'); $ page-> setConfig ('next', 'next page '); $ page-> setConfig ('last', 'Last page'); $ page-> setConfig ('first ', 'homepage'); $ page-> setConfig ('theme ', '% FIRST % UP_PAGE % LINK_PAGE % DOWN_PAGE % END % HEADER %'); $ page-> lastSuffix = false; // The total number of pages not displayed on the last page return $ page ;}

    Call in controller PageController. class. php

    Namespace Home \ Controller; use Think \ Controller; class PageController extends Controller {public function index () {$ m = M ('user '); $ count = $ m-> count (); $ page = getpage ($ count, 8); // Common/function. pagination in php $ list = $ m-> limit ($ page-> firstRow, $ page-> listRows)-> select (); $ this-> assign ('list ', $ list); // assign a dataset $ this-> assign ('page', $ page-> show ()); // value-assigned paging output $ this-> display ();}}

    Display in View index/index.html

         
        
         

    User name:

    {$ Vo ['name']}

    {$ Page}

    Example: page.css

    .pages a,.pages span { display:inline-block; padding:2px 5px; margin:0 1px; border:1px solid #f0f0f0; -webkit-border-radius:3px; -moz-border-radius:3px; border-radius:3px;}.pages a,.pages li { display:inline-block; list-style: none; text-decoration:none; color:#58A0D3;}.pages a.first,.pages a.prev,.pages a.next,.pages a.end{ margin:0;}.pages a:hover{ border-color:#50A8E6;}.pages span.current{ background:#50A8E6; color:#FFF; font-weight:700; border-color:#50A8E6;}

    2. write paging functions in the template UserModel. class. php.

    Namespace Home \ Model; use Think \ Model; class UserModel extends Model {public function getPage () {$ page = I ('P', 0, 'int '); $ limit = 8; $ data = $ this-> page ($ page, $ limit)-> select (); $ count = $ this-> count (); $ Page = new \ Think \ Page ($ count, $ limit); $ Page-> lastSuffix = false; // whether to display the total number of pages $ Page-> setConfig ('header ','
  • Total% TOTAL_ROW %Images per page'. $ Limit .'Frame% NOW_PAGE %/% TOTAL_PAGE %Page
  • '); $ Page-> setConfig ('prev', 'Previous page'); $ Page-> setConfig ('next', 'next page '); $ Page-> setConfig ('last', 'Last page'); $ Page-> setConfig ('first ', 'homepage'); $ Page-> setConfig ('theme ', '% FIRST % UP_PAGE % LINK_PAGE % DOWN_PAGE % END % HEADER %'); $ show = $ Page-> show (); return array ('list' => $ data, 'page' => $ show );}}

    Call in controller PageController. class. php

    Namespace Home \ Controller; use Think \ Controller; class PageController extends Controller {public function index () {$ m = D ('upload _ img '); $ list = $ m-> getPage (); // pagination in the model $ this-> assign ('list', $ list ); // assign a dataset $ this-> display ();}}

    View display index/index.html

         
        
         

    User name:

    {$ Vo ['name']}

    {$ List. page}

    The format of the page Sharding is the same as that in page.css in the public example on the 1st.
    Above Reference the file constant "_ CSS _" and configure it in the public configuration file:

     return array(   'TMPL_PARSE_STRING'=>array(  '__CSS__'=>.'/Public/Css', ))

    The above is all the content of this article. I hope it will be helpful to everyone's learning, and I hope you can support your own home.

    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.