2015-04-04 80 views
1

在Laravel 5中,我使用simplePagination,如docs中所述。我想定製輸出,而不是雙人字形&rdaquo; ''',我可以放一個右箭頭。但是我無法在任何地方看到它來定製它。Laravel 5分頁定製

有誰知道這裏的文檔在哪裏?或從哪裏開始尋找?

+0

我不能告訴如果[第二個答案以SO問題](http://stackoverflow.com/questions/26148645/laravel-show-only-next-and-previous-link-in-pagination)可以幫助,它提到o使用自定義文本來編寫上一個/下一個鏈接的默認文本。 – SaschaM78 2015-04-04 12:37:46

+0

耶看起來很近 - 但我認爲這是L4。 L5看不到任何類似的東西。 – mattl 2015-04-04 15:28:59

回答

1

雖然它是無證的,但它當然是可能的。這與Laravel 4幾乎相同。基本上所有你需要的是創建一個自定義主持人幷包裝paginator實例。

這裏是一個演示如何可能看起來像:

use Illuminate\Contracts\Pagination\Paginator; 
use Illuminate\Contracts\Pagination\Presenter; 
use Illuminate\Pagination\BootstrapThreeNextPreviousButtonRendererTrait; 
use Illuminate\Pagination\UrlWindow; 
use Illuminate\Pagination\UrlWindowPresenterTrait; 

class CustomPresenter implements Presenter 
{ 
    use BootstrapThreeNextPreviousButtonRendererTrait, UrlWindowPresenterTrait; 

    private $paginator; 

    private $window; 

    public function __construct(Paginator $paginator, UrlWindow $window = null) 
    { 
     $this->paginator = $paginator; 
     $this->window = is_null($window) ? UrlWindow::make($paginator) : $window->get(); 
    } 

    public function render() 
    { 
     if ($this->hasPages()) { 
      return sprintf(
       '<ul class="pagination">%s %s %s</ul>', 
       $this->getPreviousButton("Previous"), 
       $this->getLinks(), 
       $this->getNextButton("Next") 
      ); 
     } 

     return null; 
    } 

    public function hasPages() 
    { 
     return $this->paginator->hasPages() && count($this->paginator->items() !== 0); 
    } 

    protected function getDisabledTextWrapper($text) 
    { 
     return '<li class="disabled"><span>'.$text.'</span></li>'; 
    } 

    protected function getActivePageWrapper($text) 
    { 
     return '<li class="active"><span>'.$text.'</span></li>'; 
    } 

    protected function getDots() 
    { 
     return $this->getDisabledTextWrapper("..."); 
    } 

    protected function currentPage() 
    { 
     return $this->paginator->currentPage(); 
    } 

    protected function lastPage() 
    { 
     return $this->paginator->lastPage(); 
    } 

    protected function getAvailablePageWrapper($url, $page, $rel = null) 
    { 
     $rel = is_null($rel) ? '' : ' rel="'.$rel.'"'; 

     return '<li><a href="'.htmlentities($url).'"'.$rel.'>'.$page.'</a></li>'; 
    } 
} 
從控制器

然後:

public function index() 
    { 
     $users = User::paginate(5); 
     $presenter = new CustomPresenter($users); 

     return view("home.index")->with(compact('users', 'presenter')); 
    } 

的觀點:

@foreach ($users as $user) 
    <div>{{ $user->email }}</div> 
@endforeach 
{!! $presenter->render() !!} 
+0

謝謝。稍後會有一些改進。復活節快樂。 – mattl 2015-04-05 07:32:21

+0

感謝 - 繼續從你的建議我最終使我自己的SimpleBootstrapThreePresenter.php版本。這隻需要編輯兩行。但感謝讓我開始。 – mattl 2015-04-05 13:11:59