클래스 페이지 {
비공개 $total;//총 수량
비공개 $limit; //mysql의 제한문 반환
private $pageStart;//시작값
private $pageStop;//끝값
private $pageNumber;//페이징 번호 개수 표시
private $ page;//현재 페이지
private $pageSize;//각 페이지에 표시되는 숫자
private $pageToatl;//총 페이지 수
private $pageParam;//Paging 변수
private $uri ;//URL 매개변수
/**
* 페이징 설정 스타일은 대소문자를 구분하지 않습니다
* %pageToatl% //전체 페이지 수
* %page%//현재 페이지
* %pageSize% //표시되는 데이터 항목 수 현재 페이지에서
* %pageStart%//이 페이지의 시작 항목 수
* %pageStop%//이 페이지의 끝 항목 수
* %total%//총 데이터 항목 수
* %first%// 홈페이지
* %ending%//마지막 페이지
* %up%//이전 페이지
* %down%//다음 페이지
* %F %//시작 페이지
* %E%//끝 페이지
* %omitFA%//앞 생략 및 점프
* %omitEA%//뒤 생략 및 점프
* %omitF%/ /앞 생략 및 점프
* %omitE%//다음 생략
* %numberF%//숫자 페이징 고정 개수
* %numberD%//왼쪽 및 오른쪽 동일한 숫자 페이징
* % input%//입력박스 점프
* %GoTo%//점프 버튼
*/ bbs.it-home.org
private $pageType = '페이지 %page%/total %pageToatl % page %first%%up%%F%%omitFA%%numberF%%omitEA%%E%%down%%ending%';
//표시 값 설정
private $pageShow = array ('첫번째'=>'홈페이지','종료'=>'마지막 페이지','위'=>'이전 페이지','아래'=>'다음 페이지','이동'=> ;'GO');
/**
* 초기화 데이터, 구축 방법
* @access public
* @param int $total 총 데이터량
* @param int $pageSize 페이지당 표시되는 항목 수
* @param int $ pageNumber 페이징 번호는 숫자를 표시합니다(%numberF%와 %numberD%를 사용하면 다른 효과가 나타납니다)
* @param string $pageParam 페이징 변수
* @return void
*/
공개 함수 __construct($total,$pageSize=10,$pageNumber=5,$ pageParam=' p'){
$this->total = $total$this->pageSize = $pageSize $this- >pageNumber = $pageNumber$this->pageParam = $pageParam;
$this->calculate();
}> ;
/**
* 페이지 매김 표시
* @access public
* @return string HTML 페이지 매김 문자열
*/
공개 함수 pageShow(){
$this->uri();
if($this->pageToatl>1 ){
if($this->page == 1){
$first = ''.$this->pageShow['first'] span>';$up = ''.$this->pageShow['up'].' ';
} else{
$first = ''.$this->pageShow[ '첫 번째' ].' ';
$up = ''.$this->pageShow['up'].' ';
}
if($this-> ;page > ;= $this->pageToatl){
$ending = ''.$this->pageShow['ending'].' 🎜>$down = ''.$this->pageShow['down'].' ';
}else{
$ending = ''.$this- >pageShow ['ending'].' ';
$down = ''.$this->pageShow['down'].' ';
}
$input = 'page.'" onkeydown="javascript: if(event.keyCode==13){var value =parseInt(this.value); var page =(value> ;'.$this->pageToatl.') ? '.$this->pageToatl.' : value=''.$this->uri.'&'.$this-> =' 페이지 ''; return false;}">';
$GoTo = ''.$this->pageShow['GoTo'].' ';
}else{
$first = '';$ up =' ';$ending = '';$down = '';$input = '';$GoTo = '';
}
$this->numberF();
return str_ireplace(array('%pageToatl%','%page%','%pageSize%','%pageStart%','%pageStop%', ' %total%','%first%','%ending%','%up%','%down%','%input%','%GoTo%'),array($this->; pageToatl ,$this->page,$this->pageStop-$this->pageStart,$this->pageStart,$this->pageStop,$this->total,$first,$ending,$up,$down,$ input,$GoTo),$this->pageType);
}
/**
*數字分頁
*/
原生函數numberF(){
$pageF = stripos($this->pageType,'%numberF%');
$pageD = stripos($this->pageType,'%numberD%');
$numberF = '';$numberD = '' ;$F = '';$E ='';$omitF = '';$omitFA = '';$omitE = '';$omitEA = '';
if($pageF!==false || $pageD!==false){
if($pageF!==false){
$number = $this->pageNumber%2==0 ?$this->pageNumber/2:($this- >pageNumber 1)/2;
$DStart = $this->page - $numberpage - $number- 1:0;
if($this->頁$number- $DStart > $this->pageToatl){
$DStop = ($this->頁$number-$DStart) - $this->pageToatl;
$forStop = $this->pageToatl 1;
}else{
$DStop = 0;
$forStop = $this->頁$number- $DStart 1;
}
$forStart = $this->page-$number-$ DStop頁-$number-$DStop;
for($ i=$forStart;$iif($i==$this->page){
$numberF .= ''.$i.' ; ';
}else{
$numberF .= ''.$i.' ';
}
}
}
if($pageD!==false){
$number = $this- >pageNumber ;
$forStart = $this->page-$number>0?$this->page-$number:1;
$forStop = $this->page $number>$ $$this->pageToatl 1 :$this->第$number 1;
for($i=$forStart;$ipage; $i){
$numberD .= ''.$i.' ';
}
$numberD .= ''.$this->頁。 >第1 頁;for($i=$start;$i$numberD .= ''.$i.' ';
}
}
$F = $forStart>1?'uri.'&'.$this->pageParam.'=1">1':'' ;
$E = $forStop pageToatl 1?''.$this->pageToatl.'':'';if($forStart>2){
$omitF = '…
';
$startA = $this->page-$numberpage-$number;
$ omitFA = 'uri.'&'.$this->pageParam.'='.$startA.'">… ;';
}
if($forStoppageToatl){
$omitE = '… ';
$stopA = $this->頁$number> $ $this->pageToatl:$this->page $number;
$omitEA = '… ';
}
}
$this->pageType = str_ireplace(array('%F%','% E%', '%omitFA%','%omitEA%','%omitF%','%omitE%','%numberF%','%numberD%'),陣列($F,$E,$ omitFA,$omitEA ,$omitF,$omitE,$numberF,$numberD),$this->pageType);
}
/**
*處理url的方法
* @access public
* @param array $url 保持URL直對關係數組
* @return string 過濾後的url尾參數
*/
函數uri() {
$url = $_SERVER["REQUEST_URI"];
$ par = parse_url($url);
if (isset($par['query'])) {
parse_str($ par['query'],$query);
if(!is_array( $this->uri)){
$this->uri = array();
}
array_merge($ query,$this->uri);
unset($query [$this->pageParam]);
while($key = array_search('',$query)){
unset($query [$key]);
}
$this ->uri = $par['path'].'?'.http_build_query($query);
}else{
$this-> uri = $par['path'].'?' ;
}
}
/**
* 設定limit方法及計算起始條數與結束條數
*/
創函數calculate(){
$this->pageToatl = ceil($this->total/$this ->pageSize) ;
$this->page = intval($_GET[$this->pageParam]);
$this->page = $this->page>=1? $this->page>$this->pageToatl?$this->pageToatl:$this->page:1;
$this->pageStart = ($this->page-1) *$this->pageSize ;
$this->pageStop = $this->pageStart $this->pageSize;
$this->pageStop = $this->pageStop>$this ->總計? ->pageStop;
$this->limit = $this->pageStart.','.$this->pageStop;
}
/**
* 設定過濾器
* /
public function __set($name,$value){
switch($name){
case 'pageType':
case 'uri':
$this->$name = $value;
return;
case 'pageShow':
if(is_array($value)){
$this->pageShow = array_merge($this->pageShow,$value);
}
return;
}
}
;/**
* 取值過濾器
*/
public function __get($name){
switch ( $name){
case 'limit':
case 'pageStart':
case ' pageStop':
return $this->$name;
預設:
return;
}
}
}
複製程式碼