tp6自定义分页,分页类修改

浏览908

Tp6分页驱动在配置里面没法自定义,如果想显示分页总数的话可以自定义,修改分页类,路径:\vendor\topthink\think-orm\src\paginator\driver\Bootstrap.php

最终效果:

image.png

实现方法:

在class下面加上总页面:

    // 总页码
    protected function getTotal(){
        $html='<li><a>共<strong>'.$this->lastPage.'</strong>页/<strong>'.$this->total().'</strong>条</a></li>';
        return $html;
    }

image.png

渲染分页处修改:

    /**
     * 渲染分页html
     * @return mixed
     */
    public function render()
    {
        if ($this->hasPages()) {
            if ($this->simple) {
                return sprintf(
                    '<ul class="pager">%s %s</ul>',
                    $this->getPreviousButton(),
                    $this->getNextButton()
                );
            } else {
                return sprintf(
                    '<ul class="pagination">%s %s %s %s</ul>',
                    $this->getPreviousButton(),
                    $this->getLinks(),
                    $this->getNextButton(),
                    $this->getTotal()
                );
            }
        }
    }

image.png



  • 暂无任何回答