示例: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
效果如下: