laravel4 添加分页

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 = '&raquo;')/*最后一页*/
	{
		// 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('&lt; 首页');
 
            echo $presenter->getPrevious('&lt; 上一页');
 

            echo $presenter->getPageRange($start, $end);
 
            echo $presenter->getNext('下一页 &gt;');
            
            echo $presenter->getLast('最后一页 &gt;');
            
        ?>
    </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

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值