开发环境 PHP5.6 MySQL5.7
ThinkPHP默认的分页模板
自定义分页模板
实现代码currentPage() <= 1) { return $this->getDisabledTextWrapper($str); } $url = $this->url(1); return $this->getPageLinkWrapper($url, $str); } //TODO : 上一页 protected function getPreviousButton($text = '«') { if ($this->currentPage() <= 1) { return $this->getDisabledTextWrapper($text); } $url = $this->url( $this->currentPage() - 1 ); return $this->getPageLinkWrapper($url, $text); } //TODO : 页码 protected function getLinks() { if ($this->total > $this->listRows) { if ($this->lastPage < $this->bnumber) { return $this->getUrlLinks($this->getUrlRange(1, $this->lastPage)); } else { $min = 1; if ($this->currentPage > $this->bnumber / 2) $min = $this->currentPage - floor($this->bnumber / 2); if ($this->lastPage - $this->currentPage < $this->bnumber / 2) $min = $this->lastPage - $this->bnumber + 1; return $this->getUrlLinks($this->getUrlRange($min, $min + $this->bnumber - 1)); } } } //TODO : 下一页 protected function getNextButton($text = '»') { if (!$this->hasMore) { return $this->getDisabledTextWrapper($text); } $url = $this->url($this->currentPage() + 1); return $this->getPageLinkWrapper($url, $text); } //TODO : 末页 protected function getlastButton($text = '') { if (!$this->hasMore) { return $this->getDisabledTextWrapper($text); } $url = $this->url($this->lastPage()); return $this->getPageLinkWrapper($url, $text); } //TODO : 渲染页 public function render() { //数据是否足够分页 if ($this->hasPages()) { return sprintf( '
- %s %s %s %s %s
4.1 将 TpPageHelper.php 放在extend\tool下4.2 修改默认模板4.3 项目链接:http://pan.baidu.com/s/1miIIcmG 密码:wwnl