- /**
- * 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 ();
- This is the View code.
-
- {$ Page}
-
3. paging style
- . 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}
|