The ThinkPHP3.2.3 paging method is described in detail, and thinkphp3.2.3 Paging

Source: Internet
Author: User

The ThinkPHP3.2.3 paging method is described in detail, and thinkphp3.2.3 Paging

This example describes how ThinkPHP3.2.3 implements paging. We will share this with you for your reference. The details are as follows:

The first thing to understand is that ThinkPHP3.2.3's paging class has been moved to Think \ Page. class. php, which is somewhat different from the previous version. It is similar to the previous version, but the default effect is not flattering, so it is best to add some styles on your own.

I added some styles (not very nice). You can improve the paging style on your own ,:

Here I made the page settings into a function getpage, and put this method into Application \ Common \ function. php (note that the function is not a class) to facilitate calling elsewhere. The Code is as follows:

<? Php/*** encapsulate the same code of the TODO basic page, less front-end code * @ param $ count total number of records to be paged * @ param int $ pagesize number of queries per Page * @ return \ Think \ Page */function getpage ($ count, $ pagesize = 10) {$ p = new Think \ Page ($ count, $ pagesize); $ p-> setConfig ('header ', '<li class = "rows"> total records <B> % TOTAL_ROW % </B> page <B> % NOW_PAGE % </B>/total <B> % TOTAL_PAGE % </B> page </li> '); $ p-> setConfig ('prev', 'previous page'); $ p-> setConfig ('Next', 'next page'); $ p-> setConfig ('last ', 'Last page '); $ P-> setConfig ('first ', 'homepage'); $ p-> setConfig ('Theme ', '% FIRST % UP_PAGE % LINK_PAGE % DOWN_PAGE % END % HEADER %'); $ p-> lastSuffix = false; // The last page is not displayed as the total number of pages. return $ p;}?>

The code used in the controller is as follows:

Public function showAllUsers () {$ m = M ('user'); $ where = "id> 10"; $ count = $ m-> where ($ where) -> count (); $ p = getpage ($ count, 1); $ list = $ m-> field (true)-> where ($ where) -> order ('id')-> limit ($ p-> firstRow, $ p-> listRows)-> select (); $ this-> assign ('select ', $ list); // assign a dataset $ this-> assign ('page', $ p-> show ()); // value-assigned paging output $ this-> display ();}

Next use in View:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

The sample mypage.css for setting the page sharding is as follows:

.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;}

In this way, you can.

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.