Tangframework paging implementation

Source: Internet
Author: User
Tangframework pagination is a service registered. You only need to implement the IPaginator interface to use a custom pagination class without namespaceTangPagination; useTangI18nII18n; * ** implement by PAGE ** ClassPaginator * @ packageTangPagination * classPaginatorimplementsIPaginator {priv

Tangframework Pagination is a service registered. You only need to implement the IPaginator interface to use a custom Pagination class without the namespace Tang \ Pagination; use Tang \ I18n \ II18n; /*** Paginator * Class Paginator * @ package Tang \ Pagination */class Paginator implements IPaginator {priv

Tangframework pagination is a service registered. You only need to implement the IPaginator interface to use the custom pagination class, <无>
Namespace Tang \ Pagination; use Tang \ I18n \ II18n;/*** implement * Class Paginator * @ package Tang \ Pagination */class Paginator implements IPaginator {private $ total = 0; private $ pageNumber = 20; private $ maxPage = 0; private $ nowPage = 0;/*** Language Pack * @ var II18n */private $ II18n; public function setl18n (II18n $ II18n) {$ this-> II18n = $ II18n;}/*** set the total ** @ param $ total * @ return mixed */public function SetTotal ($ total) {$ total = (int) $ total; $ total <0 & $ total = 0; $ this-> total = $ total ;} /*** set the number of pages per page * @ param $ pageNumber * @ return mixed */public function setPageNumber ($ pageNumber) {$ pageNumber = (int) $ pageNumber; $ pageNumber <1 & $ pageNumber = 20; $ this-> pageNumber = $ pageNumber;}/*** get the number of pages per page * @ return int */public function getPageNumber () {return $ this-> pageNumber;}/*** get the maximum number of pages * @ Return int */public function getMaxPage () {return $ this-> maxPage;}/*** get the current page * @ return int */public function getNowPage () {return $ this-> nowPage ;} /*** retrieve the paging array * @ param int $ nowPage current page * @ param int $ total number * @ param int $ pageNumber one page number * @ throws NowPageLtMaxPageException * @ return array * /public function getPages ($ nowPage, $ total = 0, $ pageNumber = 0) {if ($ total) {$ this-> setTotal ($ Total) ;}if ($ pageNumber) {$ this-> setPageNumber ($ pageNumber) ;}$ nowPage = (int) $ nowPage; $ nowPage <1 & $ nowPage = 1; $ this-> nowPage = $ nowPage; $ maxPage = $ this-> maxPage = ceil ($ this-> total/$ this-> pageNumber); if (! $ MaxPage) {return false;} if ($ nowPage> $ maxPage) {throw new NowPageLtMaxPageException ('No more pages! ', Null, 50013);} $ pages = array (); $ pages [] = array ('name' => $ this-> II18n-> get ('first page'), 'page' => 1 ); if ($ nowPage> 1) {$ pages [] = array ('name' => $ this-> II18n-> get ('prev page '), 'page' => $ nowPage-1);} if ($ nowPage> 5) {for ($ I = $ nowPage-5; $ I <$ nowPage; $ I ++) {if ($ I <= 0) continue; $ pages [] = array ('name' => $ I, 'page' => $ I );} for ($ I = 0; $ I <5; $ I ++) {$ p = $ nowPage + $ I; if ($ p> $ maxPage) {break ;} $ pages [] = array ('name' => $ p, 'page' => $ p) ;}} else {for ($ I = 1; $ I <10; $ I ++) {if ($ I >$ maxPage) {break;} $ pages [] = array ('name' => $ I, 'page' => $ I) ;}}$ nextPage = $ nowPage + 1; if ($ nowPage <$ maxPage) {$ pages [] = array ('name' => $ this-> II18n-> get ('Next page'), 'page' => $ nextPage );} $ pages [] = array ('name' => $ this-> II18n-> get ('end page'), 'page' => $ maxPage ); return $ pages ;}}
Namespace Tang \ Pagination; use Tang \ I18n \ II18n; use Tang \ Interfaces \ ISetConfig; /*** paging Interface * interface IPaginator * @ package Tang \ Pagination */Interface IPaginator {/*** set Language Pack * @ param II18n $ II18n * @ return void */public function setl18n (II18n $ II18n ); /*** set the total ** @ param $ total * @ return void */public function setTotal ($ total ); /*** set the number of pages per page * @ param $ pageNumber * @ return void */public function setPageNumber ($ pageNumber ); /*** get the number of pages * @ return int */public function getPageNumber ();/*** get the maximum number of pages * @ return int */public function getMaxPage (); /*** get the current page * @ return int */public function getNowPage (); /* ** retrieve the array by page * returns an array of results (* array ('name' => 'first page', 'page' => 1 ), * array ('name' => '1', 'page' => 1), * array ('name' => '2', 'page' => 2 ), * array ('name' => 'Next page', 'page' => 2 )*) form * @ param int $ nowPage current page * @ param int $ total quantity * @ param int $ pageNumber one page quantity * @ return array */public function getPages ($ nowPage, $ total = 0, $ pageNumber = 0 );}

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.