ThinkPHP paging implementation. ThinkPHP paging implementation TP3.2 framework manual, there is a data paging, but every time you have to write too much code, there are some troubles such as Chinese settings, as a program developer, it is necessary to sort out ThinkPHP paging implementation
In the TP3.2 framework manual, there is a data paging, but too much code should be written every time, and there are some troubles in Chinese settings. as a program developer, it is necessary to sort it out:
I. paging method
/**
* The same code encapsulation of the TODO basic paging makes the front-end code less
* @ Param $ m model, reference transfer
* @ Param $ where query condition
* @ Param int $ pagesize number of entries per page
* @ Return \ Think \ Page
*/
Function getpage (& $ m, $ where, $ pagesize = 10 ){
$ M1 = clone $ m; // copy a model.
$ Count = $ m-> where ($ where)-> count (); // the join and other operations are reset after the connected operation.
$ M = $ m1; // copy a model to keep it in a fixed connection operation.
$ P = new Think \ Page ($ count, $ pagesize );
$ P-> lastSuffix = false;
$ P-> setConfig ('header ','
Total% TOTAL_ROW %Records per page% LIST_ROW %Entry% NOW_PAGE %Page/total% TOTAL_PAGE %Page');
$ P-> setConfig ('prev', 'Previous page ');
$ P-> setConfig ('next', 'next ');
$ P-> setConfig ('last', 'Last page ');
$ P-> setConfig ('first ', 'homepage ');
$ P-> setConfig ('theme ',' % FIRST % UP_PAGE % LINK_PAGE % DOWN_PAGE % END % HEADER % ');
$ P-> parameter = I ('Get .');
$ M-> limit ($ p-> firstRow, $ p-> listRows );
Return $ p;
}
The getpage method can be placed in the Application/Common/function of the TP framework. php. this document can be specifically used to place some common methods where they can be called (such as Controller files and View files ).
II. call the paging method
$ M = M ('products ');
$ P = getpage ($ m, $ where, 10 );
$ List = $ m-> field (true)-> where ($ where)-> order ('Id desc')-> select ();
$ This-> list = $ list;
$ This-> page = $ p-> show ();
View code
{$ Page}
3. Finally, it is the paging style. this is a bit messy, because the background framework has been downloaded online, and the style has not been prepared yet. this style can also be implemented by itself, which is simple.
. Pagination ul {
Display: inline-block;
Margin-bottom: 0;
Margin-left: 0;
-Webkit-border-radius: 3px;
-Moz-border-radius: 3px;
Border-radius: 3px;
-Webkit-box-shadow: 0 1px 2px rgba (0.05, 0 );
-Moz-box-shadow: 0 1px 2px rgba (0.05, 0 );
Box-shadow: 0 1px 2px rgba (0, 0, 0, 0.05 );
}
. Pagination ul li {
Display: inline;
}
. Pagination ul li. rows {
Line-height: 30px;
Padding-left: 5px;
}
. Pagination ul li. rows B {color: # f00}
. Pagination ul li a,. pagination ul li span {
Float: left;
Padding: 4px 12px;
Line-height: 20px;
Text-decoration: none;
Background-color: # fff;
Background: url ('../images/bottom_bg.png') 0px 0px;
Border: 1px solid # d3dbde;
/* Border-left-width: 0 ;*/
Margin-left: 2px;
Color: # 08c;
}
. Pagination ul li a: hover {
Color: red;
Background: # 0088cc;
}
. Pagination ul li. first-child a,. pagination ul li. first-child span {
Border-left-width: 1px;
-Webkit-border-bottom-left-radius: 3px;
Border-bottom-left-radius: 3px;
-Webkit-border-top-left-radius: 3px;
Border-top-left-radius: 3px;
-Moz-border-radius-bottomleft: 3px;
-Moz-border-radius-topleft: 3px;
}
. Pagination ul. disabled span,. pagination ul. disabled a,. pagination ul. disabled a: hover {
Color: #999;
Cursor: default;
Background-color: transparent;
}
. Pagination ul. active a,. pagination ul. active span {
Color: #999;
Cursor: default;
}
. Pagination ul li a: hover,. pagination ul. active a,. pagination ul. active span {
Background-color: # f0c040;
}
. Pagination ul li. last-child a,. pagination ul li. last-child span {
-Webkit-border-top-right-radius: 3px;
Border-top-right-radius: 3px;
-Webkit-border-bottom-right-radius: 3px;
Border-bottom-right-radius: 3px;
-Moz-border-radius-topright: 3px;
-Moz-border-radius-bottomright: 3px;
}
. Pagination ul li. current a {color: # f00; font-weight: bold; background: # ddd}
Http://www.bkjia.com/PHPjc/894183.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/894183.htmlTechArticleThinkPHP paging implementation TP3.2 framework manual, there is a data paging, but every time you have to write too much code, there are some troubles such as Chinese settings, as a program developer, it is necessary to sort out...