laravel實現分頁樣式調換示例代碼(增加首、尾頁)

更新:2017-10-25    編輯:凝芙    來源:GeGuai.com    人氣:加載中...    字號:|

標簽:實現  分頁  替換  示例  樣式  代碼  百度搜索

前言

本文主要給大家介紹了關于laravel分頁樣式調換的相關內容,分享出來供大家參考學習,,下面話不多說了,來一起看看詳細的介紹吧。

法子如下:

一、自定義一個類(代碼如下),位置隨你放,注意命名空間

二、模板輸出調用 {!! $data->render(new \App\Http\Controllers\ShmilyThreePresenter($data)) !!}

最終樣式

laravel實現分頁樣式調換示例代碼(增加首、尾頁)

實現代碼

<?php //創建繼承自 Illuminate\Pagination\BootstrapThreePresenter 類,這里我把類放在了Controllers下面,需要改動BootstrapThreePresenter 類的哪些法子就重寫哪個法子。如果認為默認的bootstrap樣式和你項目的樣式不符,可以自定義樣式。 namespace App\Http\Controllers; use Illuminate\Contracts\Pagination\Paginator as PaginatorContract; use Illuminate\Contracts\Pagination\Presenter as PresenterContract; class ShmilyThreePresenter extends \Illuminate\Pagination\BootstrapThreePresenter { /** * Convert the URL window into Bootstrap HTML. * * @return string */ public function render() { if ($this->hasPages()) { return sprintf( '<ul>%s %s %s %s %s</ul>',//自定義class樣式 $this->firstPage(),//添加首頁法子 $this->getPreviousButton('上一頁'), $this->getLinks(), $this->getNextButton('下一頁'), $this->last()//添加尾頁法子 ); } return ''; } /** * Get HTML wrapper for an available page link. * * @param string $url * @param int $page * @param string|null $rel * @return string */ protected function getAvailablePageWrapper($url, $page, $rel = null) { $rel = is_null($rel) ? '' : ''; return '<li><a href="'.htmlentities($url).'" '.$rel.'>'.$page.'</a></li>'; //這里li標簽可以添加你自己的class樣式 } /** * Get HTML wrapper for disabled text. * * @param string $text * @return string */ protected function getDisabledTextWrapper($text) { return '<li><span>'.$text.'</span></li>'; } /** * Get HTML wrapper for active text. * * @param string $text * @return string */ protected function getActivePageWrapper($text) { return '<li><span>'.$text.'</span></li>'; } /** * Get the next page pagination element. * * @param string $text * @return string */ //新建首頁法子 public function firstPage($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->paginator->currentPage() <= 1) { return $this->getDisabledTextWrapper($text); } $url = $this->paginator->url(1); return $this->getPageLinkWrapper($url, $text, 'first'); } /** * Get the next page pagination element. * * @param string $text * @return string */ //新建尾頁法子 public function last($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. $url = $this->paginator->url($this->paginator->lastPage()); return $this->getPageLinkWrapper($url, $text, 'last'); } }

總結


評論列表(網友評論僅供網友表達個人看法,并不表明本站同意其觀點或證實其描述)

站點導航

您可能在找這些
黑龙江快乐十分走势图