The thinkPHP framework allows you to add complete sample code for the js event paging class.

Source: Internet
Author: User
This article mainly introduces the pagination class customPage for adding js events in the thinkPHP framework. class. php provides the pagination class customPage in the form of a complete instance. class. php implementation code and analysis of ajax dynamic loading of data, set paging links and other functions, friends who need to refer to the next article mainly introduces thinkPHP framework can add js events pagination class customPage. class. php provides the pagination class customPage in the form of a complete instance. class. php implementation code and analysis of ajax dynamic loading of data, set pagination links and other functions, friends can refer to the following

This example describes the paging class customPage. class. php that can be added to the thinkPHP framework. We will share this with you for your reference. The details are as follows:

The paging class used for ajax to dynamically load data. paging events can be dynamically added to remove the href address in link.


  
 
  
'% TOTAL_ROW % record', 'prev' => 'previous page', 'next' => 'next page', 'First '=> '1... ', 'last' => '... % TOTAL_PAGE % ', 'theme' => '% FIRST % UP_PAGE % LINK_PAGE % DOWN_PAGE % END % ',); /*** architecture function ** @ param array $ total number of records of totalRows * @ param array $ number of records displayed on each page of listRows * @ param array $ parameter for paging jump */public function construct ($ totalRows, $ listRows = 20, $ parameter = array () {C ('Var _ page') & $ this-> p = C ('Var _ page ');/ /Set the paging parameter name/* Basic Settings */$ this-> totalRows = $ totalRows; // set the total number of records $ this-> listRows = $ listRows; // set the number of lines displayed on each page. $ this-> parameter = empty ($ parameter )? $ _ GET: $ parameter; $ this-> nowPage = empty ($ _ GET [$ this-> p])? 1: intval ($ _ GET [$ this-> p]); $ this-> totalPages = ceil ($ this-> totalRows/$ this-> listRows ); // total page number if ($ this-> nowPage> $ this-> totalPages) {$ this-> nowPage = $ this-> totalPages ;} $ this-> nowPage = $ this-> nowPage> 0? $ This-> nowPage: 1; $ this-> firstRow = $ this-> listRows * ($ this-> nowPage-1 );} /*** custom paging link setting * @ param string $ name set name * @ param string $ value set value */public function setConfig ($ name, $ value) {if (isset ($ this-> config [$ name]) {$ this-> config [$ name] = $ value ;}} /*** generate link URL * @ param integer $ page number * @ return string */private function url ($ PAGE) {return str_replace (urlencode ('[page]'), $ page, $ This-> url);}/*** assemble the paging link * @ return string */public function show () {if (0 = $ this-> totalRows) return '';/* generate URL */$ this-> parameter [$ this-> p] = '[ PAGE] '; $ this-> url = U (ACTION_NAME, $ this-> parameter);/* calculate the page information */if (! Empty ($ this-> totalPages) & $ this-> nowPage> $ this-> totalPages) {$ this-> nowPage = $ this-> totalPages ;} /* calculate the temporary paging variable */$ now_cool_page = $ this-> rollPage/2; $ now_cool_page_ceil = ceil ($ now_cool_page ); $ this-> lastSuffix & $ this-> config ['last'] = $ this-> totalPages; // Previous Page $ up_row = $ this-> nowPage-1; $ up_page = $ up_row> 0? 'Previous page ': ''; // Next Page $ down_row = $ this-> nowPage + 1; $ down_page = ($ down_row <= $ this-> totalPages )? 'Next Page': ''; // The first page $ the_first = ''; if ($ this-> totalPages> $ this-> rollPage & ($ this-> nowPage-$ now_cool_page) >=1) {$ the_first = 'first page ';} // The Last Page $ the_end = ''; // if ($ this-> totalPages> $ this-> rollPage & ($ this-> nowPage + $ now_cool_page) <$ this-> totalPages) {if ($ this-> totalPages> $ this-> rollPage & ($ this-> nowPage + $ now_cool_page) <$ this-> totalPages) {$ the_end = 'totalrows. '"href =" expose Crip T :; "rel =" external nofollow "=" external nofollow "> Last page ';} for ($ I = 1; $ I <= $ this-> rollPage; $ I ++) {if ($ this-> nowPage-$ now_cool_page) <= 0) {$ page = $ I;} elseif ($ this-> nowPage + $ now_cool_page-1) >=$ this-> totalPages) {$ page = $ this-> totalPages-$ this-> rollPage + $ I;} else {$ page = $ this-> nowPage-$ now_cool_page _ Ceil + $ I;} if ($ page> 0 & $ page! = $ This-> nowPage) {if ($ page <= $ this-> totalPages) {$ link_page. = ('
  
  • '. $ Page .'
  • ');} Else {break;} else {if ($ page> 0 & $ this-> totalPages! = 1) {$ link_page. = ('
  • '. $ Page .'
  • ') ;}} If (! Empty ($ link_page) $ link_page ='
      '. $ Link_page .'
    '; // Replace the page content $ page_str = str_replace (array (' % HEADER % ',' % NOW_PAGE % ',' % UP_PAGE % ',' % DOWN_PAGE % ', '% FIRST %', '% LINK_PAGE %', '% END %', '% TOTAL_ROW %', '% TOTAL_PAGE % '), array ($ this-> config ['head'], $ this-> nowPage, $ up_page, $ down_page, $ the_first, $ link_page, $ the_end, $ this-> totalRows, $ this-> totalPages), $ this-> config ['theme ']); $ page_str = trim ($ page_str); if (! Empty ($ page_str) $ page_str. ='

    Jump '; return $ page_str ;}}

    The above is the details of the complete sample code of the paging class that can be added to js events in the thinkPHP framework. For more information, see other related articles in the first PHP community!

    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.