复制\thinkphp\library\think下的Paginator.php修改为另一个名称,例如改为Apaginator.php,把abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable,其中的Paginator修改为Apaginator,关闭保存
第二步
复制文件夹paginator,后修改文件夹名字,可以在前面也加个a字,打开文件夹中的Bootstrap.php,修改文件名为Abootstrap.php,并把class Bootstrap extends Paginator修改为namespace think\apaginator\driver;use think\Apaginator;class Abootstrap extends Apaginator,关闭保存
第三步
打开\thinkphp\library\think\db下的Query.php找到
public function paginate($listRows = null, $simple = false, $config = []){
}
复制并修改如下
public function apaginate($listRows = null, $simple = false, $config = [])
{
if (is_int($simple)) {
$total = $simple;
$simple = false;
}
if (is_array($listRows)) {
$config = array_merge(Config::get('apaginate'), $listRows);
$listRows = $config['list_rows'];
} else {
$config = array_merge(Config::get('apaginate'), $config);
$listRows = $listRows ?: $config['list_rows'];
}
/** @var aPaginator $class */
$class = false !== strpos($config['type'], '\\') ? $config['type'] : '\\think\\apaginator\\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();
}
return $class::make($results, $listRows, $page, $total, $simple, $config);
}
第四步
\application下的config.php,打开修改
//分页配置1
'paginate' => [
'type' => 'bootstrap',
'var_page' => 'page',
'list_rows' => 20,
],
//分页配置2
'apaginate' => [
'type' => 'abootstrap',
'var_page' => 'page1',
'list_rows' => 20,
],
第五步
在控制器中使用paginate(10);apaginate(10);就可以了
最佳答案
