Omnipotent paging-PHP source code

Source: Internet
Author: User
Omnipotent paging class
Init (1000, 20); * $ page-> setNotActiveTemplate ('{a}'); * $ page-> setActiveTemplate ('{}'); * echo $ page-> show (); *** @ author wind place */class Page {/*** total number of items */private $ total; /*** page size */private $ pageSize;/***** total page size */private $ pageNum;/***** current page */private $ page; /*** address */private $ uri;/*** paging variable */private $ pageParam;/*** limit xx, XX */private $ limit; /*** display the number by page */private $ listnum = 8; /***** pagination display template * available variable parameter * {total} total number of data entries * {pagesize} number of entries per page * {start} number of entries starting on this page * {end} number of entries ending on this page * {pagenum} total number of pages * {frist} homepage * {pre} Previous Page * {next} next Page * {last} last Page * {list} number page * {goto} jump button */private $ template = 'total {total} pieces of data. {pagesize} pieces of data are displayed on each page, A total of {start}-{end} data entries on this page {pagenum} page {frist} {pre} {list} {next} {last} {goto }'; /*** selected paging link template */private $ activeTemplate = '{text}';/*** unselected paging link template */private $ notActi VeTemplate = '{text}';/*** display text setting */private $ config = array ('frist '=> 'homepage ', 'pre' => 'previous page', 'next' => 'next page', 'last' => 'Last page '); /*** initialize * @ param type $ total number of items * @ param type $ pageSize size per page * @ param type $ param url additional parameter * @ param type $ pageParam paging variable * /public function init ($ total, $ pageSize, $ param = '', $ pageParam = 'page') {$ this-> total = intval ($ total ); $ this-> pageSize = intval ($ pageSize ); $ This-> pageParam = $ pageParam; $ this-> uri = $ this-> geturi ($ param ); $ this-> pageNum = ceil ($ this-> total/$ this-> pageSize); $ this-> page = $ this-> setPage (); $ this-> limit = $ this-> setlimit ();}/*** set the paging template * @ param type $ template configuration */public function setTemplate ($ template) {$ this-> template = $ template;}/*** set the selected page template * @ param type $ activeTemplate template configuration */public function setActiveTemplate ($ activ ETemplate) {$ this-> activeTemplate = $ activeTemplate;}/*** set the unspecified page template * @ param type $ notActiveTemplate template configuration */public function setNotActiveTemplate ($ notActiveTemplate) {$ this-> notActiveTemplate = $ notActiveTemplate;}/*** return page * @ return type */public function show () {return str_ireplace (array ('{total }', '{pagesize}', '{start}', '{end}', '{pagenum}', '{frist}', '{pre }', '{next}', '{last }', '{List}', '{goto}',), array ($ this-> total, $ this-> setPageSize (), $ this-> star (), $ this-> end (), $ this-> pageNum, $ this-> frist (), $ this-> prev (), $ this-> next (), $ this-> last (), $ this-> pagelist (), $ this-> gopage (),), $ this-> template );} /*** get the start number of limit * @ return type */public function getOffset () {return ($ this-> page-1) * $ this-> pageSize ;} /*** set LIMIT * @ return type */private function setlimit () {Return "limit ". ($ this-> page-1) * $ this-> pageSize. ", {$ this-> pageSize}";}/*** get limit * @ param type $ args * @ return type */public function _ get ($ args) {if ($ args = "limit") {return $ this-> limit;} else {return null ;}} /*** initialize the current page * @ return int */private function setPage () {if (! Empty ($ _ GET [$ this-> pageParam]) {if ($ _ GET [$ this-> pageParam]> 0) {if ($ _ GET [$ this-> pageParam]> $ this-> pageNum) return $ this-> pageNum; else return $ _ GET [$ this-> pageParam] ;}} return 1 ;} /*** initialize url * @ param type $ param * @ return string */private function geturi ($ param) {$ url = $ _ SERVER ['request _ url']. (strpos ($ _ SERVER ['request _ URI '], "? ")? "":"? "). $ Param; $ parse = parse_url ($ url); if (isset ($ parse ["query"]) {parse_str ($ parse ["query"], $ params ); unset ($ params ["page"]); $ url = $ parse ["path"]. "? ". Http_build_query ($ params); return $ url;} else {return $ url;}/*** number of entries starting on this page * @ return int */private function star () {if ($ this-> total = 0) {return 0;} else {return ($ this-> page-1) * $ this-> pageSize + 1 ;}} /*** number of end entries on the current page * @ return type */private function end () {return min ($ this-> page * $ this-> pageSize, $ this-> total);}/*** set the current page size * @ return type */private function setPageSize (){ Return $ this-> end ()-$ this-> star () + 1;}/*** homepage * @ return type */private function frist () {$ html = ''; if ($ this-> page = 1) {$ html. = $ this-> replace ("{$ this-> uri} & page = 1", $ this-> config ['frist '], true );} else {$ html. = $ this-> replace ("{$ this-> uri} & page = 1", $ this-> config ['frist '], false );} return $ html;}/*** previous page * @ return type */private function prev () {$ html = ''; if ($ this-> page> 1) {$ html. = $ this-> replace ($ this-> uri. '& page = '. ($ this-> page-1), $ this-> config ['pre'], false);} else {$ html. = $ this-> replace ($ this-> uri. '& page = '. ($ this-> page-1), $ this-> config ['pre'], true);} return $ html ;} /*** paging number list * @ return type */private function pagelist () {$ linkpage = ""; $ lastlist = floor ($ this-> listnum/2 ); for ($ I = $ lastlist; $ I >=1; $ I --) {$ page = $ this-> page-$ I; I F ($ page> = 1) {$ linkpage. = $ this-> replace ("{$ this-> uri} & page = {$ page}", $ page, false) ;}else {continue ;}$ linkpage. = $ this-> replace ("{$ this-> uri} & page = {$ this-> page}", $ this-> page, true ); for ($ I = 1; $ I page + $ I; if ($ page pageNum) {$ linkpage. = $ this-> replace ("{$ this-> uri} & page = {$ page}", $ page, false);} else {break ;}} return $ linkpage;}/*** Next Page * @ return type */private function Next () {$ html = ''; if ($ this-> page <$ this-> pageNum) {$ html. = $ this-> replace ($ this-> uri. '& page = '. ($ this-> page + 1), $ this-> config ['Next'], false);} else {$ html. = $ this-> replace ($ this-> uri. '& page = '. ($ this-> page + 1), $ this-> config ['Next'], true);} return $ html ;} /*** last page * @ return type */private function last () {$ html = ''; if ($ this-> page = $ this-> pageNum) {$ html. = $ this-> replace ($ This-> uri. '& page = '. ($ this-> pageNum), $ this-> config ['last'], true);} else {$ html. = $ this-> replace ($ this-> uri. '& page = '. ($ this-> pageNum), $ this-> config ['last'], false);} return $ html ;} /*** jump button * @ return string */private function gopage () {$ html = ''; $ html. = ''; return $ html ;} /*** template replacement * @ param type $ replace content * @ param type $ result condition * @ return type */private function replace ($ url, $ Text, $ result = true) {$ template = ($ result? $ This-> activeTemplate: $ this-> notActiveTemplate); $ html = str_replace ('{url}', $ url, $ template ); $ html = str_replace ('{text}', $ text, $ html); return $ html ;}}

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.