app/config/view.php:
'pagination' => 'pagination.slider',
在vendor/laravel/framework/src/Illuminate/Pagination/Presenter.php 添加2个函数
public function getIndex($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);
}
$url = $this->paginator->getUrl(1);
return $this->getPageLinkWrapper($url, $text, 'prev');
}
public function getLast($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);
}
$url = $this->paginator->getUrl($this->lastPage);
return $this->getPageLinkWrapper($url, $text, 'next');
}
在app/views/pagination/slider.php:
<?php
$presenter = new Illuminate\Pagination\BootstrapPresenter($paginator);
?>
<?php if ($paginator->getLastPage() > 1): ?>
<div class="pagination">
<ul>
<?php
/* How many pages need to be shown before and after the current page */
$showBeforeAndAfter = 3;
/* Current Page */
$currentPage = $paginator->getCurrentPage();
$lastPage = $paginator->getLastPage();
/* Check if the pages before and after the current really exist */
$start = $currentPage - $showBeforeAndAfter;
/*
Check if first page in pagination goes below 1, and substract that from
$showBeforeAndAfter var so the pagination won't start with page 0 or below
*/
if($start < 1){
$diff = $start - 1;
$start = $currentPage - ($showBeforeAndAfter + $diff);
}
$end = $currentPage + $showBeforeAndAfter;
if($end > $lastPage){
$diff = $end - $lastPage;
$end = $end - $diff;
}
echo $presenter->getIndex('< 首页');
echo $presenter->getPrevious('< 上一页');
echo $presenter->getPageRange($start, $end);
echo $presenter->getNext('下一页 >');
echo $presenter->getLast('最后一页 >');
?>
</ul>
</div>
<?php endif; ?>
app/controllers/admin/PageController.php:
public function index(){
return \View::make('admin.pages.index')->with('pages',Page::orderBy('created_at')->paginate(5));
}
app/views/admin/pages/index.blade.php 在列表尾部添加:
{{ $pages->links() }}
转载于:https://my.oschina.net/u/234439/blog/472533