From f19f517c944152fcea5799c3a821498181089a21 Mon Sep 17 00:00:00 2001 From: yunwuxin <448901948@qq.com> Date: Wed, 6 Jul 2016 19:00:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B3=A8=E9=87=8A=20?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Model.php | 1 + library/think/paginator/driver/Bootstrap.php | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/library/think/Model.php b/library/think/Model.php index 63122af5..4865c3e3 100644 --- a/library/think/Model.php +++ b/library/think/Model.php @@ -34,6 +34,7 @@ use think\paginator\Collection as PaginatorCollection; * @method static integer avg($field = '*') AVG查询 * @method static setField($field, $value = '') * @method static Query where($field, $op = null, $condition = null) 指定AND查询条件 + * @method static static findOrFail($data = null) 查找单条记录 如果不存在则抛出异常 * */ abstract class Model implements \JsonSerializable, \ArrayAccess diff --git a/library/think/paginator/driver/Bootstrap.php b/library/think/paginator/driver/Bootstrap.php index be65ecfc..87e1fe48 100644 --- a/library/think/paginator/driver/Bootstrap.php +++ b/library/think/paginator/driver/Bootstrap.php @@ -66,23 +66,23 @@ class Bootstrap extends Paginator 'last' => null ]; - $length = 3; + $side = 3; + $window = $side * 2; - if ($this->lastPage < $length * 4) { + if ($this->lastPage < $window + 6) { $block['first'] = $this->getUrlRange(1, $this->lastPage); - } elseif ($this->currentPage <= $length * 2) { - $block['first'] = $this->getUrlRange(1, $length * 2 + 2); + } elseif ($this->currentPage <= $window) { + $block['first'] = $this->getUrlRange(1, $window + 2); $block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage); - } elseif ($this->currentPage > ($this->lastPage - $length * 2)) { + } elseif ($this->currentPage > ($this->lastPage - $window)) { $block['first'] = $this->getUrlRange(1, 2); - $block['last'] = $this->getUrlRange($this->lastPage - $length * 2 + 2, $this->lastPage); + $block['last'] = $this->getUrlRange($this->lastPage - ($window + 2), $this->lastPage); } else { $block['first'] = $this->getUrlRange(1, 2); - $block['slider'] = $this->getUrlRange($this->currentPage - $length, $this->currentPage + $length); + $block['slider'] = $this->getUrlRange($this->currentPage - $side, $this->currentPage + $side); $block['last'] = $this->getUrlRange($this->lastPage - 1, $this->lastPage); } - $html = ''; if (is_array($block['first'])) { @@ -132,7 +132,7 @@ class Bootstrap extends Paginator * 生成一个可点击的按钮 * * @param string $url - * @param int $page + * @param int $page * @return string */ protected function getAvailablePageWrapper($url, $page) @@ -193,7 +193,7 @@ class Bootstrap extends Paginator * 生成普通页码按钮 * * @param string $url - * @param int $page + * @param int $page * @return string */ protected function getPageLinkWrapper($url, $page)