lizhen_gitee 1 年之前
父节点
当前提交
3f8319c807
共有 1 个文件被更改,包括 21 次插入0 次删除
  1. 21 0
      thinkphp/library/think/db/Query.php

+ 21 - 0
thinkphp/library/think/db/Query.php

@@ -1438,6 +1438,27 @@ class Query
         return $this;
     }
 
+    //模仿上一个page,但是从paginate拿到page与list_rows
+    public function autopage(){
+        $config = Config::get('paginate');
+
+        /** @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;
+
+        //list_rows
+        $listRows = isset($_REQUEST['listrow']) ? (int)$_REQUEST['listrow'] : $config['list_rows'];
+
+
+        $this->options['page'] = [intval($page), intval($listRows)];
+        return $this;
+    }
+
     /**
      * 分页查询
      * @param int|array $listRows 每页数量 数组表示配置参数