Thinkphp paging implementation, thinkphp Paging
The above is my Implementation of thinkphp paging effect, two methods, one is to call the Function Method in public functions (refer to the http://www.cnblogs.com/tianguook/p/4326613.html), one is to write paging method 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 ', '<li> total <B> % TOTAL_ROW % </B> Records & nbsp; <B> % NOW_PAGE % </B>/<B> % TOTAL_PAGE % </B> page </li> '); $ 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 ();
$ Limit = 8; $ page = getpage ($ count, $ limit); // Common/function. pagination in php $ list = $ m-> limit ($ page-> firstRow, $ page-> listRows)-> select ();
/** Or $ page1 = I ('P', 0, 'int ');
$ List = $ m-> limit ($ page1, $ limit)-> select (); */$ this-> assign ('LIST', $ list ); // assign a value to the dataset $ this-> assign ('page', $ page-> show (); // assign a value to the paging output $ this-> display ();}}
Display in view index/index.html
<! DOCTYPE html>
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 ', '<li> total <B> % TOTAL_ROW % </B> Images & nbsp; per page <B> '. $ limit. '</B> frame & nbsp; <B> % NOW_PAGE % </B>/<B> % TOTAL_PAGE % </B> Page </li> '); $ 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
<! DOCTYPE html>
The format of the page sharding is the same as that in page.css in the public example on the 1st.
The preceding <link href = "_ CSS _/page.css" rel = "stylesheet"/> reference file constant "_ CSS _" is configured in the public configuration file:
return array(
'TMPL_PARSE_STRING'=>array( '__CSS__'=>__ROOT__.'/Public/Css', )
)