12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- /**
- * Page.php UTF-8
- * 页面处理
- *
- * @date : 2018/5/21 20:08
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huolib\tool;
- use think\Config;
- use think\Paginator;
- use think\Session;
- class Page {
- /**
- * 分页查询
- *
- * @param array $list 列表数据
- * @param int $count
- * @param int $page
- * @param int $offset
- * @param array $config 配置参数
- * page:当前页,
- * path:url路径,
- * query:url额外参数,
- * fragment:url锚点,
- * var_page:分页变量,
- * list_rows:每页数量
- * type:分页类名
- *
- * @return \think\Paginator
- */
- public static function paginate($count, $list, $page, $offset, $config = []) {
- $_simple = false;
- $_total = 0;
- if (is_int($count)) {
- $_total = $count;
- }
- $_offset = $offset;
- $_config = array_merge(Config::get('paginate'), $config);
- $_offset = $_offset ?: request()->param('list_rows/d', 0);
- if (empty($_offset)) {
- $_offset = Session::get('list_rows');
- } else {
- Session::set('list_rows', $_offset);
- }
- $_offset = $_offset ?: $_config['list_rows'];
- /** @var Paginator $_class */
- $_class = false !== strpos($_config['type'], '\\')
- ? $_config['type']
- : '\\think\\paginator\\driver\\'.ucwords(
- $_config['type']
- );
- $_page = $page < 1 ? 1 : $page;
- $_config['path'] = isset($_config['path']) ? $_config['path'] : call_user_func([$_class, 'getCurrentPath']);
- return $_class::make($list, $_offset, $_page, $_total, $_simple, $_config);
- }
- }
|