ThinkPHP 分頁實現,thinkphp分頁實現_PHP教程

來源:互聯網
上載者:User

ThinkPHP 分頁實現,thinkphp分頁實現


TP3.2架構手冊,有一個資料分頁,不過每次都要寫太多的代碼,還有中文設定等有些麻煩,做為程式開發人員,有必要整理下:

O、先看

一、分頁方法

/** * TODO 基礎分頁的相同代碼封裝,使前台的代碼更少 * @param $m 模型,引用傳遞 * @param $where 查詢條件 * @param int $pagesize 每頁查詢條數 * @return \Think\Page */function getpage(&$m,$where,$pagesize=10){    $m1=clone $m;//淺複製一個模型    $count = $m->where($where)->count();//連慣操作後會對join等操作進行重設    $m=$m1;//為保持在為定的連慣操作,淺複製一個模型    $p=new Think\Page($count,$pagesize);    $p->lastSuffix=false;    $p->setConfig('header','
  • %TOTAL_ROW%條記錄 每頁%LIST_ROW%條 第%NOW_PAGE%頁/共%TOTAL_PAGE%
  • '); $p->setConfig('prev','上一頁'); $p->setConfig('next','下一頁'); $p->setConfig('last','末頁'); $p->setConfig('first','首頁'); $p->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%'); $p->parameter=I('get.'); $m->limit($p->firstRow,$p->listRows); return $p;}

    getpage方法可以放在TP架構的 Application/Common/Common/function.php,這個文檔可以專門放置一些通用的方法,在哪裡都可以調用(如:Controller檔案,View檔案等)。

    二、調用分頁方法

    $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代碼

      {$page}

    三、最後就是分頁的樣式了,這個有些亂,因後台架構網上下載的,樣式還沒來的及整理,這個樣式也可以自己實現,簡單的。

    .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}


    thinkphp 怎實現分頁與郵件發送

    TP的分頁其實是很簡單的:
    首先你需要匯入分頁類。
    代碼如下:

    $User = M('User'); // 執行個體化User對象
    import('ORG.Util.Page');// 匯入分頁類
    $count = $User->where('status=1')->count();// 查詢滿足要求的總記錄數
    $Page = new Page($count,25);// 執行個體化分頁類 傳入總記錄數和每頁顯示的記錄數
    $show = $Page->show();// 分頁顯示輸出
    // 進行分頁資料查詢 注意limit方法的參數要使用Page類的屬性
    $list = $User->where('status=1')->order('create_time')->limit($Page->firstRow.','.$Page->listRows)->select();
    $this->assign('list',$list);// 賦值資料集
    $this->assign('page',$show);// 賦值分頁輸出
    $this->display(); // 輸出模板
     

    thinkphp 資料分頁(文章分頁)

    文章分頁,我記得應該有個thinkphpcms的 你找找那個 安裝一遍看看那個怎麼寫的。。你行的 - -
     

    http://www.bkjia.com/PHPjc/893202.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/893202.htmlTechArticleThinkPHP 分頁實現,thinkphp分頁實現 TP3.2架構手冊,有一個資料分頁,不過每次都要寫太多的代碼,還有中文設定等有些麻煩,做為程式開發...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.