以前使用tp5的分頁paginate類時只用到了第一個參數,也就是每頁顯示多少行數組
今天又仔細看了下手冊和paginate類,發現paginate可傳入的參數有不少,能夠知足更多需求this
好比能夠指定分頁的數據,可使用重寫的分頁類等。。。url
下面是tp5.1的分頁類spa
/** * 分頁查詢 * @access public * @param int|array $listRows 每頁數量 數組表示配置參數 * @param int|bool $simple 是否簡潔模式或者總記錄數 * @param array $config 配置參數 * page:當前頁, * path:url路徑, * query:url額外參數, * fragment:url錨點, * var_page:分頁變量, * list_rows:每頁數量 * type:分頁類名 * @return \think\Paginator * @throws DbException */ public function paginate($listRows = null, $simple = false, $config = []) { if (is_int($simple)) { $total = $simple; $simple = false; } $paginate = Container::get('config')->pull('paginate'); if (is_array($listRows)) { $config = array_merge($paginate, $listRows); $listRows = $config['list_rows']; } else { $config = array_merge($paginate, $config); $listRows = $listRows ?: $config['list_rows']; } /** @var Paginator $class */ $class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\paginator\\driver\\' . ucwords($config['type']); $page = isset($config['page']) ? (int) $config['page'] : call_user_func([ $class, 'getCurrentPage', ], $config['var_page']); $page = $page < 1 ? 1 : $page; $config['path'] = isset($config['path']) ? $config['path'] : call_user_func([$class, 'getCurrentPath']); if (!isset($total) && !$simple) { $options = $this->getOptions(); unset($this->options['order'], $this->options['limit'], $this->options['page'], $this->options['field']); $bind = $this->bind; $total = $this->count(); $results = $this->options($options)->bind($bind)->page($page, $listRows)->select(); } elseif ($simple) { $results = $this->limit(($page - 1) * $listRows, $listRows + 1)->select(); $total = null; } else { $results = $this->page($page, $listRows)->select(); } $this->removeOption('limit'); $this->removeOption('page'); return $class::make($results, $listRows, $page, $total, $simple, $config); }