From fc8f05abc9dbec0e662f411940b03f792c274fd6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 26 Sep 2016 16:07:42 +0800 Subject: [PATCH] =?UTF-8?q?Query=E7=B1=BB=E5=88=86=E9=A1=B5=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E7=AC=AC=E4=BA=8C=E4=B8=AA=E5=8F=82=E6=95=B0=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BC=A0=E5=85=A5=E6=80=BB=E8=AE=B0=E5=BD=95=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/db/Query.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/library/think/db/Query.php b/library/think/db/Query.php index b498b1ea..53bbbe85 100644 --- a/library/think/db/Query.php +++ b/library/think/db/Query.php @@ -972,7 +972,7 @@ class Query /** * 分页查询 * @param int|null $listRows 每页数量 - * @param bool $simple 简洁模式 + * @param int|bool $simple 简洁模式或者总记录数 * @param array $config 配置参数 * page:当前页, * path:url路径, @@ -986,6 +986,10 @@ class Query */ public function paginate($listRows = null, $simple = false, $config = []) { + if (is_int($simple)) { + $total = $simple; + $simple = false; + } $config = array_merge(Config::get('paginate'), $config); $listRows = $listRows ?: $config['list_rows']; @@ -1000,16 +1004,15 @@ class Query $config['path'] = isset($config['path']) ? $config['path'] : call_user_func([$class, 'getCurrentPath']); - if (!$simple) { + if (!isset($total) && !$simple) { $options = $this->getOptions(); $total = $this->count(); $bind = $this->bind; $results = $this->options($options)->bind($bind)->page($page, $listRows)->select(); } else { $results = $this->limit(($page - 1) * $listRows, $listRows + 1)->select(); - $total = null; + $total = isset($total) ? $total : null; } - return $class::make($results, $listRows, $page, $total, $simple, $config); }