ThinkPHP5 custom page style, thinkphp5 custom page

Source: Internet
Author: User

ThinkPHP5 custom page style, thinkphp5 custom page

1. Create a file Page. php In the thinkphp/library/think/paginator/driver directory.

Note namespace and inheritance

<? Phpnamespace think \ paginator \ driver; use think \ Paginator; class Page extends Paginator {public $ rollPage = 5; // Number of pages displayed on each Page in the Page bar // homepage protected function home () {if ($ this-> currentPage ()> 1) {return "<a href = '". $ this-> url (1 ). "'title = 'homepage'> homepage </a>" ;}else {return "<p> homepage </p>" ;}// previous page protected function prev () {if ($ this-> currentPage ()> 1) {return "<a href = '". $ this-> url ($ this-> currentPage-1 ). "'title = 'preput'> previous page </a>" ;}else {return "<p> previous page </p>" ;}// next page protected function next () {if ($ this-> hasMore) {return "<a href = '". $ this-> url ($ this-> currentPage + 1 ). "'title = 'Next page'> next page </a>" ;}else {return "<p> next page </p> ";}} // protected function last () {if ($ this-> hasMore) {return "<a href = '". $ this-> url ($ this-> lastPage ). "'title = 'tail'> tailpage </a>";} else {return "<p> tailpage </p> ";}} // statistical information protected function info () {return "<p class = 'pageremark'> total <B> ". $ this-> lastPage. "</B> page <B> ". $ this-> total. "</B> data entries </p>";}/*** page number button * @ return string */protected function getLinks () {if ($ this-> simple) return ''; $ block = ['first' => null, 'slider' => null, 'last' => null]; $ rollPage = $ this-> rollPage; // Number of pages displayed on each page in the pagination bar $ nowPage = floor ($ rollPage/2); // calculate the temporary paging variable if ($ this-> lastPage <= $ rollPage) {$ block ['first'] = $ this-> getUrlRange (1, $ this-> lastPage);} else if ($ this-> currentPage <= $ nowPage) {$ block ['first'] = $ this-> getUrlRange (1, $ rollPage );} else if ($ this-> currentPage >=( $ this-> lastPage-$ nowPage )) {$ block ['first'] = $ this-> getUrlRange ($ this-> lastPage-$ rollPage + 1, $ this-> lastPage );} else {$ block ['first'] = $ this-> getUrlRange ($ this-> currentPage-$ nowPage, $ this-> currentPage + $ nowPage );} $ html = ''; if (is_array ($ block ['first']) {$ html. = $ this-> getUrlLinks ($ block ['first']);} return $ html;}/*** render pagination html * @ return mixed */public function render () {if ($ this-> hasPages () {if ($ this-> simple) {return sprintf ('% s <div class = "pagination"> % s </div>', $ this-> css (), $ this-> prev (), $ this-> getLinks (), $ this-> next ());} else {return sprintf ('% s <div class = "pagination"> % s </div> ', $ this-> css (), $ this-> home (), $ this-> prev (), $ this-> getLinks (), $ this-> next (), $ this-> last (), $ this-> info ());}}} /*** generate a clickable button ** @ param string $ url * @ param int $ page * @ return string */protected function getAvailablePageWrapper ($ url, $ page) {return '<a href = "'. htmlentities ($ url ). '"title =" nth "'. $ page. '"page"> '. $ page. '</a>';}/*** generate a disabled button ** @ param string $ text * @ return string */protected function getDisabledTextWrapper ($ text) {return '<p class = "pageEllipsis"> '. $ text. '</p>';}/*** generates an activation button ** @ param string $ text * @ return string */protected function getActivePageWrapper ($ text) {return '<a href = "" class = "cur"> '. $ text. '</a>';}/*** generate the ellipsis button ** @ return string */protected function getDots () {return $ this-> getDisabledTextWrapper ('... ');}/*** generate page numbers in batches. ** @ param array $ urls * @ return string */protected function getUrlLinks (array $ urls) {$ html = ''; foreach ($ urls as $ page => $ url) {$ html. = $ this-> getPageLinkWrapper ($ url, $ page);} return $ html ;} /*** generate common page number button ** @ param string $ url * @ param int $ page * @ return string */protected function getPageLinkWrapper ($ url, $ page) {if ($ page = $ this-> currentPage () {return $ this-> getActivePageWrapper ($ page);} return $ this-> getAvailablePageWrapper ($ url, $ page);}/*** paging style */protected function css () {return '<style type = "text/css">. pagination p {margin: 0; cursor: pointer }. pagination {height: 40px; padding: 20px 0px ;}. pagination a {display: block; float: left; margin-right: 10px; padding: 2px 12px; height: 24px; border: 1px # cccccc solid; background: # fff; text-decoration: none; color: #808080; font-size: 12px; line-height: 24px ;}. pagination a: hover {color: #077ee3; background: white; border: 1px #077ee3 solid ;}. pagination. cur {border: none; background: #077ee3; color: # fff ;}. pagination p {float: left; padding: 2px 12px; font-size: 12px; height: 24px; line-height: 24px; color: # bbb; border: 1px # ccc solid; background: # fcfcfc; margin-right: 8px ;}. pagination p. pageRemark {border-style: none; background: none; margin-right: 0px; padding: 4px 0px; color: #666 ;}. pagination p. pageRemark B {color: red ;}. pagination p. pageEllipsis {border-style: none; background: none; padding: 4px 0px; color: #808080 ;}. dates li {font-size: 14px; margin: 20px 0 }. dates li span {float: right} </style> ';}}

2. modify the application/config configuration file

// Configure 'paginate' => ['type' => 'page', 'var _ page' => 'page ', 'list _ rows '=> 15,],

Effect: Limit the number of pages per page.

2-6 pages are displayed when you click 4. Similarly, 3-7 pages are displayed when you click 5, that is, only 5 page numbers are displayed each time.

 

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.