thinkphp 5.0+ 点击分页带上其他参数

thinkphp5.0+ 下的分页方法,文件地址是:thinkphp\thinkphp\library\think\db\Query.php

/**
     * 分页查询
     * @param int|null $listRows 每页数量
     * @param int|bool $simple   简洁模式或者总记录数
     * @param array    $config   配置参数
     *                           page:当前页,
     *                           path:url路径,
     *                           query:url额外参数,
     *                           fragment:url锚点,
     *                           var_page:分页变量,
     *                           list_rows:每页数量
     *                           type:分页类名
     * @return \think\paginator\Collection
     * @throws DbException
     */
    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'];

        /** @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();
            $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();
        }
        return $class::make($results, $listRows, $page, $total, $simple, $config);
    }

很多时候我们都需要根据条件查询数据,直接get提交查询的话就会生成所谓的叫做普通模式路由模式,然鹅我们使用paginate这个方法只传第一个参数的时候,点击分页发现搜索的参数并没有带上,所以我们就要用到后面的参数了,第二个参数simple config : 配置参数,
page:当前页,
path:url路径,
query:url额外参数,
fragment:url锚点,
var_page:分页变量,
list_rows:每页数量
type:分页类名
这里有一个 query:url额外参数,,我们加上这个配置参数就可以把搜索的条件带上了。

前面省略  ->paginate(20, false, [
        'query' => input('param.'),
    ]);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章