PHP Page-Out class
Total_rows = $data [' total_rows ']; $this->parameter =!empty ($data [' parameter '])? $data [' parameter ']: '; $this->list_rows =!empty ($data [' list_rows ']) && $data [' list_rows '] <= 100? $data [' List_rows ']: $this->total_pages= ceil ($this->total_rows/$this->list_rows); $this->page_name =!empty ($data [' page_name '])? $data [' page_name ']: ' P '; $this->ajax_func_name=!empty ($data [' ajax_func_name '])? $data [' Ajax_func_name ']: '; $this->method =!empty ($data [' method '])? $data [' method ']: ';/* Current Page */if (!empty ($data [' now_page ')) {$this->now_page = intval ($data [' now_page ']);} else{$this->now_page =!empty ($_get[$this->page_name])? intval ($_get[$this->page_name]): 1;} $this->now_page = $this->now_page <= 0? 1: $this->now_page;if (!empty ($this->total_pages) && $this->now_page > $this->total_pages) {$ This->now_page = $this->total_pages;} $this->first_row = $this->list_rows * ($this->now_PAGE-1);} /** * Get Current Connection * @param $page * @param $text * @return string */protected function _get_link ($page, $text) {switch ($this, method) {case ' ajax ': $parameter = '; if ($this->parameter) {$parameter = ', '. $this->parameter;} Return ' Ajax_func_name. ' (\ ' ". $page. '. $parameter. ') ' href= "javascript:void (0)" > ". $text. '' . "\ n"; break;case ' html ': $url = Str_replace ('? ', $page, $this->parameter); return '. $text. '' . "\ n"; Break;default:return ' _get_url ($page). ' > '. $text. '' . "\ n"; break;}} /** * Set Current page link */protected function _set_url () {$url = $_server[' Request_uri ']. ( Strpos ($_server[' Request_uri '), '? ')? ': '? '). $this->parameter; $parse = Parse_url ($url); if (Isset ($parse [' query '])) {parse_str ($parse [' query '], $params); Unset ($params [$this->page_name]); $url = $parse [' Path ']. Http_build_query ($params); } if (!empty ($params)) {$url. = ' & '; } $this->url = $url; }/** * Get $page URL * @param $page page * @return String */protected function _get_url ($page) { if ($this->url = = = NULL) {$this->_set_url (); }//$lable = Strpos (' & ', $this->url) = = = FALSE? ': ' & '; Return $this->url. $this->page_name. '=' . $page; /** * Gets the first page * @return String */Public Function first_page ($name = ' first page ') {if ($this->no W_page > 5) {return $this->_get_link (' 1 ', $name);} ' return '; }/** * Last page * @param $name * @return String */Public Function last_page ($name = ' last page ') {i F ($this->now_page < $this->total_pages-5) {return $this->_get_link ($this->total_pages, $name);} Return '; /** * Prev * @return String */Public Function up_page ($name = ' previous page ') {if ($this->now_page!) = 1) {return $this->_get_link ($this->now_page-1, $name);} return '; }/** * Next page * @return String */Public Function down_page ($name = ' next page ') {if ($this->now_page & Lt $this->total_pages) {return $this->_get_link ($this->now_page + 1, $name); } return '; }/** * Page style output * @param $param * @return String */Public function Show ($param = 1) {if ($this ->total_rows < 1) {return '; } $className = ' Show_ '. $param; $classNames = Get_class_methods ($this); if (In_array ($className, $classNames)) {return $this, $className (); } return '; } protected function Show_2 () {if ($this->total_pages! = 1) {$return = '; $return. = $this->up_page (' < '); for ($i = 1; $i <= $this->total_pages; $i + +) {if ($i = = $this->now_page) {$ return. = "$i \ n";} Else{if ($this->now_page-$i >=4 && $i! = 1) {$return. = "...\ n "; $i = $this->now_page-3;} Else{if ($i >= $this->now_page+5 && $i! = $this->total_pages) {$return. = "...\ n "; $i = $this->total_pages;} $return. = $this->_get_link ($i, $i). "\ n";}}} $return. = $this->down_page (' > '); return $return; }} protected function Show_1 () {$plus = $this->plus; if ($plus + $this->now_page > $this->total_pages) {$begin = $this->total_pages-$plus * 2; }else{$begin = $this->now_page-$plus; } $begin = ($begin >= 1)? $begin: 1; $return = "; $return. = $this->first_page (); $return. = $this->up_page (); for ($i = $begin, $i <= $begin + $plus * 2; $i + +) {if ($i > $this->total_pages) {break; } if ($i = = $this->now_page) {$return. = "$i \ n"; } else {$return. = $this->_get_link ($i, $i). "\ n"; }} $return. = $this->down_page (); $return. = $this->last_page (); return $return; } protected function Show_3 () {$plus = $this->plus; if ($plus + $this->now_page > $this->total_pages) {$begin = $this->total_pages-$plus * 2; }else{$begin = $this->now_page-$plus; } $begin = ($begin >= 1)? $begin: 1; $return = ' total '. $this->total_rows. ' A record is divided into '. $this->total_pages. ' Page, current section '. $this->now_page. ' Page '; $return. = ', per page '; $return. = ''; $return. = $this->first_page (). " \ n "; $return. = $this->up_page (). " \ n "; $return. = $this->down_page (). " \ n "; $return. = $this->last_page (). " \ n "; $return. = ''; for ($i = $begin; $i <= $begin +10; $i + +) {if ($i > $this->total_pages) {break; } if ($i = = $this->now_page) {$return. = ''. $i. '; } else {$return. = ''. $i. '; }} $return. = ''; return $return; }}
?
# # # #处理html静态化页面分页的情况 # # # # # # # # # parameter is the static page parameter xxx.com/20-0-0-0-40 the process environment is set to HTML # HTML note Question mark #? The position of the question mark is automatically replaced with the Whereabouts page # Now_page the current page (the static page gets not the current page so only you pass in) $params = Array (' Total_rows ' =>100, # (Must) ' method ' = ' html ', # (MUST) ' parameter ' = ' xxx.com/20-0-0-0-40-?. HTML ', # (MUST) ' Now_page ' =>$_get[' P '], # (MUST) ' List_rows ' =>10, # (optional) by default); $page = new Core_lib_page ($params); echo $page->show (1); #2 # # #处理ajax分页的情况 # # # # # # # # # ajax# JavaScript method for handling environment set to ajax_func_name Ajax paging page # parameter ajax_func_ The accompanying parameter after name defaults to NULL # Now_page not to the current page so only you pass in $params = Array (' total_rows ' =>100, ' method ' = ' ajax ', ' ajax_func_ Name ' = ' goToPage ', ' now_page ' =>1,# ' parameter ' = ' ' jiong ', ' username ', '; $page = new Core_lib_page ($ params); echo $page->show (1); #7 # added Parameter6