search
Homephp教程php手册bootstrap分页

修改page,适应bootstrap分布组件
<?php <br /> // +----------------------------------------------------------------------<br> // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]<br> // +----------------------------------------------------------------------<br> // | Copyright (c) 2006-2013 http://thinkphp.cn All rights reserved.<br> // +----------------------------------------------------------------------<br> // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )<br> // +----------------------------------------------------------------------<br> // | Author: 麦当苗儿 <zuojiazi> <http:><br> // +----------------------------------------------------------------------<br> namespace Think;<br> <br> class Page{<br>     public $firstRow; // 起始行数<br>     public $listRows; // 列表每页显示行数<br>     public $parameter; // 分页跳转时要带的参数<br>     public $totalRows; // 总行数<br>     public $totalPages; // 分页总页面数<br>     public $rollPage   = 11;// 分页栏每页显示的页数<br>     public $lastSuffix = true; // 最后一页是否显示总页数<br> <br>     private $p       = 'p'; //分页参数名<br>     private $url     = ''; //当前链接URL<br>     private $nowPage = 1;<br> <br>     // 分页显示定制<br>     private $config  = array(<br>         'header' => '<li><a>%TOTAL_ROW% 条记录</a></li>',<br>         'prev'   => '         'next'   => '>>',<br>         'first'  => '1...',<br>         'last'   => '...%TOTAL_PAGE%',<br>         'theme'  => '%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% <li><a>%NOW_PAGE%/%TOTAL_PAGE%页</a></li>',<br>     );<br> <br>     /**<br>      * 架构函数<br>      * @param array $totalRows  总的记录数<br>      * @param array $listRows  每页显示记录数<br>      * @param array $parameter  分页跳转的参数<br>      */<br>     public function __construct($totalRows, $listRows, $parameter = array()) {<br>         C('VAR_PAGE') && $this->p = C('VAR_PAGE'); //设置分页参数名称<br>         /* 基础设置 */<br>         $this->totalRows  = $totalRows; //设置总记录数<br>         $this->listRows   = $listRows;  //设置每页显示行数<br>         $this->parameter  = empty($parameter) ? $_GET : $parameter;<br>         $this->nowPage    = empty($_GET[$this->p]) ? 1 : intval($_GET[$this->p]);<br>         $this->firstRow   = $this->listRows * ($this->nowPage - 1);<br>     }<br> <br>     /**<br>      * 定制分页链接设置<br>      * @param string $name  设置名称<br>      * @param string $value 设置值<br>      */<br>     public function setConfig($name,$value) {<br>         if(isset($this->config[$name])) {<br>             $this->config[$name] = $value;<br>         }<br>     }<br> <br>     /**<br>      * 生成链接URL<br>      * @param  integer $page 页码<br>      * @return string<br>      */<br>     private function url($page){<br>         return str_replace(urlencode('[PAGE]'), $page, $this->url);<br>     }<br> <br>     /**<br>      * 组装分页链接<br>      * @return string<br>      */<br>     public function show() {<br>         if(0 == $this->totalRows) return '';<br> <br>         /* 生成URL */<br>         $this->parameter[$this->p] = '[PAGE]';<br>         $this->url = U(ACTION_NAME, $this->parameter);<br>         /* 计算分页信息 */<br>         $this->totalPages = ceil($this->totalRows / $this->listRows); //总页数<br>         if(!empty($this->totalPages) && $this->nowPage > $this->totalPages) {<br>             $this->nowPage = $this->totalPages;<br>         }<br> <br>         /* 计算分页零时变量 */<br>         $now_cool_page      = $this->rollPage/2;<br>         $now_cool_page_ceil = ceil($now_cool_page);<br>         $this->lastSuffix && $this->config['last'] = $this->totalPages;<br> <br>         //上一页<br>         $up_row  = $this->nowPage - 1;<br>         $up_page = $up_row > 0 ? '<li><a>url($up_row) . '">' . $this->config['prev'] . '</a></li>' : '';<br> <br>         //下一页<br>         $down_row  = $this->nowPage + 1;<br>         $down_page = ($down_row totalPages) ? '<li><a>url($down_row) . '">' . $this->config['next'] . '</a></li>' : '';<br> <br>         //第一页<br>         $the_first = '';<br>         if($this->totalPages > $this->rollPage && ($this->nowPage - $now_cool_page) >= 1){<br>             $the_first = '<li><a>url(1) . '">' . $this->config['first'] . '</a></li>';<br>         }<br> <br>         //最后一页<br>         $the_end = '';<br>         if($this->totalPages > $this->rollPage && ($this->nowPage + $now_cool_page) totalPages){<br>             $the_end = '<li><a>url($this->totalPages) . '">' . $this->config['last'] . '</a></li>';<br>         }<br> <br>         //数字连接<br>         $link_page = "";<br>         for($i = 1; $i rollPage; $i++){<br>             if(($this->nowPage - $now_cool_page)                  $page = $i;<br>             }elseif(($this->nowPage + $now_cool_page - 1) >= $this->totalPages){<br>                 $page = $this->totalPages - $this->rollPage + $i;<br>             }else{<br>                 $page = $this->nowPage - $now_cool_page_ceil + $i;<br>             }<br>             if($page > 0 && $page != $this->nowPage){<br> <br>                 if($page totalPages){<br>                     $link_page .= '<li><a>url($page) . '">' . $page . '</a></li>';<br>                 }else{<br>                     break;<br>                 }<br>             }else{<br>                 if($page > 0 && $this->totalPages != 1){<br>                     $link_page .= '<li><a>' . $page . '</a></li>';<br>                 }<br>             }<br>         }<br> <br>         //替换分页内容<br>         return str_replace(<br>             array('%HEADER%', '%NOW_PAGE%', '%UP_PAGE%', '%DOWN_PAGE%', '%FIRST%', '%LINK_PAGE%', '%END%', '%TOTAL_ROW%', '%TOTAL_PAGE%'),<br>             array($this->config['header'], $this->nowPage, $up_page, $down_page, $the_first, $link_page, $the_end, $this->totalRows, $this->totalPages),<br>             $this->config['theme']);<br>     }<br> }</http:></zuojiazi>

AD:真正免费,域名+虚机+企业邮箱=0元

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use