thinkphp5 页码样式修改

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'] = '&laquo;';
 }
 if (!isset($config['next_next'])) {
     $options['next_text'] = '&raquo;';
 }

 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);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值