修改laravel默认分页排版

33 篇文章 0 订阅

示例:laravel 4
1、修改文件
1) url:/vendor/laravel/src/Illuminate/Pagination/Presenter.php

/**
* Render the Pagination contents.
 *
 * @return string
 */
public function render()
{
    // The hard-coded thirteen represents the minimum number of pages we need to
    // be able to create a sliding page window. If we have less than that, we
    // will just render a simple range of page links insteadof the sliding.
    if ($this->lastPage < 7)
    {
        $content = $this->getPageRange(1, $this->lastPage);
    }
    else
    {
        $content = $this->getPageSlider();
    }
    //自定义分页方法
    return "<span class='left'>共有".$this->paginator->getTotal()."条结果</span>".$this->getHomePage().$this->getPrevious().$content.$this->getNext().$this->getEndPage()."";
}
/**
 * Get the previous page pagination element.
 *
 * @param  string  $text
 * @return string
 */
public function getPrevious($text = '上一页')
{
    // If the current page is less than or equal to one, it means we can't go any
    // further back in the pages, so we will render a disabled previous button
    // when that is the case. Otherwise, we will give it an active "status".
    if ($this->currentPage <= 1)
    {
        return $this->getDisabledTextWrapper($text);
    }
    else
    {
        $url = $this->paginator->getUrl($this->currentPage - 1);

        return $this->getPageLinkWrapper($url, $text);
    }
}
public function getHomePage($text = '首页')
{
    // If the current page is less than or equal to one, it means we can't go any
    // further back in the pages, so we will render a disabled previous button
    // when that is the case. Otherwise, we will give it an active "status".
    if ($this->currentPage == 1)
    {
        return $this->getDisabledTextWrapper($text);
    }
    else
    {
        $url = $this->paginator->getUrl(1);
        return $this->getPageLinkWrapper($url, $text);
    }
}

/**
 * Get the next page pagination element.
 *
 * @param  string  $text
 * @return string
 */
public function getNext($text = '下一页')
{
    // If the current page is greater than or equal to the last page, it means we
    // can't go any further into the pages, as we're already on this last page
    // that is available, so we will make it the "next" link style disabled.
    if ($this->currentPage >= $this->lastPage)
    {
        return $this->getDisabledTextWrapper($text);
    }
    else
    {
        $url = $this->paginator->getUrl($this->currentPage + 1);

        return $this->getPageLinkWrapper($url, $text);
    }
}
public function getEndPage($text = '尾页')
{
    // If the current page is greater than or equal to the last page, it means we
    // can't go any further into the pages, as we're already on this last page
    // that is available, so we will make it the "next" link style disabled.
    if ($this->currentPage == $this->lastPage)
    {
        return $this->getDisabledTextWrapper($text);
    }
    else
    {
        $url = $this->paginator->getUrl($this->lastPage);

        return $this->getPageLinkWrapper($url, $text);
    }
}

2)url:/vendor/laravel/src/Illuminate/Pagination/BootstrapPresenter.php

/**
* Get HTML wrapper for disabled text.
 *
 * @param  string  $text
 * @return string
 */
public function getDisabledTextWrapper($text)
{
    return '<li><a href="#">'.$text.'</a></li>';   }

/**
 * Get HTML wrapper for active text.
 *
 * @param  string  $text
 * @return string
 */
public function getActivePageWrapper($text)
{
    if($text=="上一页"){
        return '<li><a href="#" class=""></a></li>';
    }elseif($text=="下一页"){
        return '<li><a href="#" class=""></a></li>';
    }elseif(is_numeric($text)&&$text>0){
        if($text<$this->lastPage){
            return '<li><a href="#" class="sele">'.$text.'</a></li>';
        }else{
            return '<li><a href="#" class="sele">'.$text.'</a></li>';
        }
    }elseif($text=="..."){
        return '<li><a href="#" class="">...</a></li>';
    }
}

视图如下:

@if(trim($oVideos->links()))
<div class="page_num_box">
    {{$oVideos->links()}}
</div>
@endif

效果如下:
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值