核心分页默认文件的路径:tp5\thinkphp\library\think\paginator\driver\Bootstrap.php
/**
* 页码按钮
* @return string
*/
/*
protected function getLinks()
{
}
这个函数是我们要修改替换的!
我这里推荐一个:http://www.thinkphp.cn/code/3000.html
public $rollPage=1;//侧面显示个数
protected function getLinks()
{
if ($this->simple)
return '';
$block = [
'first' => null,
'slider' => null,
'last' => null
];
$side = $this->rollPage;
$window = $side * 2;
if ($this->lastPage < $window +1) {
$block['slider'] = $this->getUrlRange(1, $this->lastPage);
} elseif ($this->currentPage <= $window-1) {
$block['slider'] = $this->getUrlRange(1, $window + 1);
} elseif ($this->currentPage > ($this->lastPage - $window+1)) {
$block['slider'] = $this->getUrlRange($this->lastPage - ($window), $this->lastPage);
} else {
$block['slider'] = $this->getUrlRange($this->currentPage - $side, $this->currentPage + $side);
}
$html = '';
if (is_array($block['first'])) {
$html .= $this->getUrlLinks($block['first']);
}
if (is_array($block['slider'])) {
$html .= $this->getUrlLinks($block['slider']);
}
if (is_array($block['last'])) {
$html .= $this->getUrlLinks($block['last']);
}
return $html;
}
控制器中如何智能化设置呢?注意上面的:public $rollPage=1;//侧面显示个数
我们在控制器中的引用是这样的:
$list=$obj->where($tj)->paginate(2,false, [
‘query’ => Request::instance()->param(),//不丢失已存在的url参数
]);
$list->rollPage=2;//一定要放在$list->paginate 之后哦。这里就是重新对
分页栏每页显示的页数进行定义了。