thinkphp5 页码修改
我在写thinkphp5的时候发现它的页码样式是改不了的 所以直接对系统的页码文件进行修改 新增的部分参数采用跟 jquery.pagination.js 文件一样的参数命名 下面是部分代码:
首先 在全局的config文件中 新增参数
//分页配置
'paginate' => [
'type' => 'bootstrap',
'var_page' => 'page',
'list_rows' => 15,
'prev_text' => '<', //上一页 按钮样式
'next_text' => '>', //下一页 按钮样式
'ellipse_text' => '...', //省略的页数用什么文字表示
],
在 thinkphp\library\think\db\Query.php 中的 paginate 方法中新增
$page = $page < 1 ? 1 : $page;
if (!isset($config['prev_text'])) {
$options['prev_text'] = '«';
}
if (!isset($config['next_next'])) {
$options['next_text'] = '»';
}
if (!isset($options['ellipse_text'])) {
$options['ellipse_text'] = '...';
}
在 thinkphp\library\think\Paginator.php 中新增变量
/** @var bool 是否有下一页 */
protected $hasMore;
/** @var string 上一页 按钮样式*/
protected $previousButton;
/** @var string 下一页 按钮样式*/
protected $nextButton;
/** 省略的页数用什么文字表示*/
protected $ellipse_text;
在同一个文件中的__construct方法增加代码
$this->previousButton = $options['prev_text'];
$this->nextButton = $options['next_text'];
$this->ellipse_text = $options['ellipse_text'];
在 thinkphp\library\think\paginator\driver\Bootstrap.php 中的 getLinks方法中增加代码
if (is_array($block['slider'])) {
$html .= $this->getDots($this->ellipse_text);
$html .= $this->getUrlLinks($block['slider']);
}
if (is_array($block['last'])) {
$html .= $this->getDots($this->ellipse_text);
$html .= $this->getUrlLinks($block['last']);
}
修改render代码
public function render()
{
if ($this->hasPages()) {
if ($this->simple) {
return sprintf(
'<ul class="pager">%s %s</ul>',
$this->getPreviousButton($this->previousButton),
$this->getNextButton($this->nextButton)
);
} else {
return sprintf(
'<ul class="pagination">%s %s %s</ul>',
$this->getPreviousButton($this->previousButton),
$this->getLinks(),
$this->getNextButton($this->nextButton)
);
}
}
}
最后修改getDots函数
protected function getDots($text = '...')
{
return $this->getDisabledTextWrapper($text);
}