Laravel implements the paging style replacement sample code (adding the first and last pages) and laravel sample code

Source: Internet
Author: User

Laravel implements the paging style replacement sample code (adding the first and last pages) and laravel sample code

Preface

This article describes how to replace the laravel paging style for your reference.

The method is as follows:

1. Customize a class (the Code is as follows) and place it with you. Pay attention to the namespace.

Ii. template output call {!! $data->render(new \App\Http\Controllers\ShmilyThreePresenter($data)) !!}

Final Style

Implementation Code

<? Php // creates a class inherited from Illuminate \ Pagination \ BootstrapThreePresenter. Here, I put the class under Controllers, and I need to modify the methods of the BootstrapThreePresenter class to override the method. If you think the default bootstrap style does not match the style of your project, you can customize the style. 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 class =" M-pagination "> % s </ul> ', // customize the class style $ this-> firstPage (), // Add the Home Page Method $ this-> getpreviusbutton ('previous page'), $ this-> getLinks (), $ this-> getNextButton ('Next page '), $ this-> last () // Method for adding the last page);} 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 = n Ull) {$ rel = is_null ($ rel )? '': 'Rel = "'. $ rel. '"'; return '<li> <a href =" '.html entities ($ url ). '"rel =" external nofollow "'. $ rel. '> '. $ page. '</a> </li>'; // here, you can add your own class style to the li tag}/*** Get HTML wrapper for disabled text. ** @ param string $ text * @ return string */protected function getDisabledTextWrapper ($ text) {return '<li class = "disabled"> <span> '. $ text. '</span> </li>';}/*** Get HTML wrapper for active text. ** @ param string $ text * @ return string */protected function getActivePageWrapper ($ text) {return '<li class = "active"> <span> '. $ text. '</span> </li>';}/*** Get the next page pagination element. ** @ param string $ text * @ return string * // method for creating a home page public function firstPage ($ text = 'homepage ') {// 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 * // method for creating the last page public function last ($ text = 'tail ') {// 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 ');}}

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.