- /**
- * TODO basic paging in the same code package, making the foreground code less
- * @param $m model, reference delivery
- * @param $where Query conditions
- * @param int $pagesize number of query bars per page
- * @return \think\page
- */
- Function GetPage (& $m, $where, $pagesize =10) {
- $m 1=clone $m;//Shallow copy a model
- $count = $m->where ($where)->count ();//The JOIN operation will be reset after the operation
- $m = $m 1;//to keep the constant, shallow copy a model
- $p =new think\page ($count, $pagesize);
- $p->lastsuffix=false;
- $p->setconfig (' Header ', '
- Total %total_row% records per page %list_row% article %now_page% page/Total %total_page% page
');
- $p->setconfig (' prev ', ' prev ');
- $p->setconfig (' Next ', ' next page ');
- $p->setconfig (' Last ', ' End ');
- $p->setconfig (' first ', ' home ');
- $p->setconfig (' theme ', '%first%%up_page%%link_page%%down_page%%end%%header% ');
- $p->parameter=i (' Get. ');
- $m->limit ($p->firstrow, $p->listrows);
- return $p;
- }
Copy CodeThe GetPage method can be placed in the TP framework of the application/common/common/function.php, this document can be specifically placed in a number of common methods, where can be called (such as: Controller files, view files, etc.). Second, 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}
Copy CodeThree, pagination 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,0,0,0.05);
- -moz-box-shadow:0 1px 2px Rgba (0,0,0,0.05);
- 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}
Copy Code |