thinkphp paging method and implementation code

WBOY
Release: 2016-07-25 08:52:24
Original
907 people have browsed it
  1. /**
  2. * The same code encapsulation of TODO basic paging, making the front-end code less
  3. * @param $m model, passed by reference
  4. * @param $where query conditions
  5. * @param int $pagesize Number of queries per page
  6. * @return ThinkPage
  7. */
  8. function getpage(&$m,$where,$pagesize=10){
  9. $m1=clone $m;//Shallow copy of a model
  10. $count = $m ->where($where)->count();//After the continuous operation, join and other operations will be reset
  11. $m=$m1;//To maintain the constant continuous operation, shallow copy A model
  12. $p=new ThinkPage($count,$pagesize);
  13. $p->lastSuffix=false;
  14. $p->setConfig('header','
  15. Total%TOTAL_ROW%Records per page%LIST_ROW%Records%NOW_PAGE%Pages/Total% TOTAL_PAGE%page
  16. ');
  17. $p->setConfig('prev','previous page');
  18. $p->setConfig('next','next page');
  19. $p->setConfig('last','last page');
  20. $p->setConfig('first','first page');
  21. $p->setConfig('theme' ,'%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
  22. $p->parameter=I('get.');
  23. $m->limit($p- >firstRow,$p->listRows);
  24. return $p;
  25. }
Copy code

getpage method can be placed in Application/Common/Common/function.php of the TP framework. This document can be specially Place some common methods that can be called anywhere (such as Controller files, View files, etc.).

2. Call the paging method

  1. $m=M('products');
  2. $p=getpage($m,$where,10);
  3. $list=$m->field(true)->where($ where)->order('id desc')->select();
  4. $this->list=$list;
  5. $this->page=$p->show();
  6. This is View code
  7.  {$page}
  • Copy code

    3. Pagination style

    1. .pagination ul {
    2. display: inline-block;
    3. margin-bottom: 0;
    4. margin-left: 0;
    5. -webkit-border-radius: 3px;
    6. -moz-border-radius: 3px ;
    7. border-radius: 3px;
    8. -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    9. -moz-box-shadow: 0 1px 2px rgba(0,0,0,0.05) );
    10. box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    11. }
    12. .pagination ul li {
    13. display: inline;
    14. }
    15. .pagination ul li.rows {
    16. line-height: 30px ;
    17. padding-left: 5px;
    18. }
    19. .pagination ul li.rows b{color: #f00}
    20. .pagination ul li a, .pagination ul li span {
    21. float: left;
    22. padding: 4px 12px;
    23. line -height: 20px;
    24. text-decoration: none;
    25. background-color: #fff;
    26. background: url('../images/bottom_bg.png') 0px 0px;
    27. border: 1px solid #d3dbde;
    28. /* border-left-width: 0;*/
    29. margin-left: 2px;
    30. color: #08c;
    31. }
    32. .pagination ul li a:hover{
    33. color: red;
    34. background: #0088cc;
    35. }
    36. .pagination ul li.first-child a, .pagination ul li.first-child span {
    37. border-left-width: 1px;
    38. -webkit-border-bottom-left-radius: 3px;
    39. border-bottom-left-radius: 3px;
    40. -webkit-border-top-left-radius: 3px;
    41. border-top-left-radius: 3px;
    42. -moz-border-radius-bottomleft: 3px;
    43. -moz-border-radius-topleft: 3px ;
    44. }
    45. .pagination ul .disabled span, .pagination ul .disabled a, .pagination ul .disabled a:hover {
    46. color: #999;
    47. cursor: default;
    48. background-color: transparent;
    49. }
    50. .pagination ul .active a, .pagination ul .active span {
    51. color: #999;
    52. cursor: default;
    53. }
    54. .pagination ul li a:hover, .pagination ul .active a, .pagination ul .active span {
    55. background -color: #f0c040;
    56. }
    57. .pagination ul li.last-child a, .pagination ul li.last-child span {
    58. -webkit-border-top-right-radius: 3px;
    59. border-top-right- radius: 3px;
    60. -webkit-border-bottom-right-radius: 3px;
    61. border-bottom-right-radius: 3px;
    62. -moz-border-radius-topright: 3px;
    63. -moz-border-radius-bottomright : 3px;
    64. }
    65. .pagination ul li.current a{color: #f00;font-weight: bold; background: #ddd}
    Copy code


    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!