分页的每页数量可以通过配置全局定义

This commit is contained in:
yunwuxin
2016-05-18 16:51:23 +08:00
parent 2af19639cb
commit e093a6661e
2 changed files with 8 additions and 4 deletions

View File

@@ -209,8 +209,9 @@ return [
], ],
//分页配置 //分页配置
'paginate' => [ 'paginate' => [
'type' => 'bootstrap', 'type' => 'bootstrap',
'var_page' => 'page', 'var_page' => 'page',
'list_rows' => 15
], ],
]; ];

View File

@@ -744,7 +744,7 @@ class Query
/** /**
* 分页查询 * 分页查询
* @param int $listRows 每页数量 * @param int|null $listRows 每页数量
* @param bool $simple 简洁模式 * @param bool $simple 简洁模式
* @param array $config 配置参数 * @param array $config 配置参数
* page:当前页, * page:当前页,
@@ -752,15 +752,18 @@ class Query
* query:url额外参数, * query:url额外参数,
* fragment:url锚点, * fragment:url锚点,
* var_page:分页变量, * var_page:分页变量,
* list_rows:每页数量
* type:分页类名, * type:分页类名,
* namespace:分页类命名空间 * namespace:分页类命名空间
* @return \think\paginator\Collection * @return \think\paginator\Collection
* @throws DbException * @throws DbException
*/ */
public function paginate($listRows = 15, $simple = false, $config = []) public function paginate($listRows = null, $simple = false, $config = [])
{ {
$config = array_merge(Config::get('paginate'), $config); $config = array_merge(Config::get('paginate'), $config);
$listRows = $listRows ?: $config['list_rows'];
$class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\paginator\\driver\\') . ucwords($config['type']); $class = (!empty($config['namespace']) ? $config['namespace'] : '\\think\\paginator\\driver\\') . ucwords($config['type']);
$page = isset($config['page']) ? (int) $config['page'] : call_user_func([ $page = isset($config['page']) ? (int) $config['page'] : call_user_func([