Custom thinkphp Pagination Class

Source: Internet
Author: User
Tags php class

The first step is to introduce:

1Import (' Org/util/page '); 2 $total= M (' xxx ')Count();//gets the total number of records3 $page=NewPage ($total, 3);//Instantiation: (total, number of records displayed per page)4     5 $limit=$page->firstrow. ', '.$page->listrows;//restriction string for the limit statement for SQL: ' Limit 0,12 '6 $result= M (' xxx ')->limit ($limit),Select ();7 8 $this->assign (' XXX ',$result);9 $this->page =$page->show ();//pagination Display OutputTen //Output page display style: 34 Records 6/12 page previous next first 5 Page 1 2 3 4 5 next 5 page Last page OneAt this time ' theme ' = '%totalrow%%header%%nowpage%/%totalpage% page%uppage%%downpage%%first%%prepage%%linkpage%% Nextpage%%end% ' A  -To make a CSS style, you can modify the Page.class. PHP class, give$linkPageof <a...> plus a class:< aclass= ' num ' ...>

Step two, customize:


Customization is done mainly around the theme. You can adjust the position of the variable in the initial theme as needed, or remove it from the inside.

On the basis of no modification, use the Setconfig method to modify some of the default settings: $page->setconfig (' header ', ' member ');
The properties supported by the Setconfig method include:
Header: Header description information, default value "bar Record"
Prev: The previous page describes the information, the default value is "Previous page"
Next: The next page describes the information, the default value is "Next page"
First: Describe the information on page one, the default value is "first page"
Last: The final page describes the information, the default value is "last Page"
Theme: Pagination topic description information, including a combination of all of the above elements, set this property can change the pagination of the individual units display location .

For example, you can change:

1 $page->setconfig (' first ', ' Home '); 2 $page->setconfig (' Last ', ' End '); 3 $page->setconfig (' theme ', '%first%  %uppage%  %prepage%  %linkpage%   %nextpage%   %downpage%  %end% '); 4 5 $this $page->show ();


In addition, if you do not need to look like, have to directly modify the source code!

Use [Top N page] ... [Next n pages] Don't look good, I usually change it to << ... >>:

1 //$prePage = "<a href=". Str_replace (' __page__ ', $preRow, $url). ">". $this->rollpage. " Page </a> ";2 $prePage= "<a href= '".Str_replace(' __page__ ',$preRow,$url). "' >&lt;&lt;</a>";3 4 //$nextPage = "<a href=". Str_replace (' __page__ ', $nextRow, $url). ">". $this->rollpage. " Page </a> ";5 $nextPage= "<a href= '".Str_replace(' __page__ ',$nextRow,$url). "' >&gt;&gt;</a>";

Third, Style:

In the template:

<file/> ... <  id= ' page '></div>.... 

Css:

1 /*Style-2 #page {text-align:center; padding:20px 0 20px 0; clear:both;}3 #page a.num {border:1px solid #666; padding:2px 5px; margin:0 2px; }4 #page A.num:hover, #page span.current {color: #fff, border:1px solid #000; background: #000; text-decoration:none;} 5 #page span.disabled {border:1px solid #ccc; padding:2px 5px; margin:0 2px; Color: #ccc; }6 #page span.current {padding:2px 5px; margin:0 2px; }7 */8 9 /*Ten CSS Flickr style pagination One */ A #page{padding:3px;margin:3px;text-align:Center;} - #page a{Border:#dedfde 1px solid;padding:2px 6px;background-position:50% Bottom;Color:#0061de;margin:0 3px 0 0;text-decoration:None;} - #page a:hover{Border:#000 1px solid;Background-image:None;Color:#fff;Background-color:#0061de;} the #page a:active{Border:#000 1px solid;Background-image:None;Color:#fff;Background-color:#0061de} - #page span.current{padding:2px 6px;Font-weight:Bold;Color:#ff0084;margin:0 3px 0 0;} - #page span.disabled{padding:2px 6px;Color:#adaaad;margin:0 3px 0 0;}

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.