时间:2021-07-01 10:21:17 帮助过:4人阅读
show(); */ class pagediv { public $part1; public $part2; public $part3; public $part4; public $part5; /* 对下面的分页显示进行分割: 首页 上页 1..12 13 14 15 [16] 17 18 19 20 ...100 下页 尾页 $part1 : 首页 上页 $part2 : 1.. $part3 : 12 13 14 15 [16] 17 18 19 20 $part4 : ...100 $part5 : 下页 尾页 */ public $allPage; //总页数 public $allRocords; //总记录数 public $perPage; //每页记录数 public $showPagesNo; //显示分页栏的总页码数 显示样式里共有11个 public $currentPage; //当前页 public $urlModel; //Url链接样式 public $startHidden; //出现 1... 时的页数 开始隐藏中间页 public $endHidden; //出现 ...100 时的页数 结束隐藏中间页 public function __construct($allRocords, $perPage, $showPagesNo, $currentPage, $urlModel){ $this->allRocords = $allRocords; $this->perPage = $perPage; $this->showPagesNo = $showPagesNo; $this->currentPage = $currentPage; $this->urlModel = $urlModel; $this->allPage = $this->getAllPage(); $this->startHidden = $this->getInt(($this->showPagesNo)/2); //6 $this->endHidden = $this->allPage - $this->startHidden; //94 } public function getUrl($_index = ''){ $_current = $_index; if($_index == 'pre') $_current = $this->currentPage -1; if($_index == 'next') $_current = $this->currentPage+1; if($_index == '') $_current = $this->allPage; return $this->urlModel.$_current; } public function getAllPage(){ return $this->getInt($this->allRocords/$this->perPage); } public function getInt($_float){ $_int = $_float; if( $_index = strpos($_float,'.') == true ){ $_int = substr($_float,0,$_index); $_int++; } //没有想起ceil时的候补方案 return $_int; } public function getPart1(){ $content = '
$currentPage = $_GET['page']?$_GET['page']:1; $pagediv = new pagediv(500, 10, 5, $currentPage, 'Video.php?page='); $pages=$pagediv->show(); $smarty->assign('pages',$pages);$smarty->display('Video.html');
模板中是否有包含特殊的标记,smarty不识别。
分页类有问题。你可以用这个试试。
第%page%页/共%pageToatl%页%first%%up%%F%%omitFA%%numberF%%omitEA%%E%%down%%ending%'; //显示值设置 private $pageShow = array('first'=>'首页','ending'=>'尾页','up'=>'上一页','down'=>'下一页','GoTo'=>'GO'); /** * 初始化数据,构造方法 * @access public * @param int $total 数据总数量 * @param int $pageSize 每页显示条数 * @param int $pageNumber 分页数字显示数量(使用%numberF%和使用%numberD%会有不同的效果) * @param string $pageParam 分页变量 * @return void */ public function __construct($total,$pageSize=10,$pageNumber=5,$pageParam='p'){ $this->total = $total<0?0:$total; $this->pageSize = $pageSize<0?0:$pageSize; $this->pageNumber = $pageNumber<0?0:$pageNumber; $this->pageParam = $pageParam; $this->calculate(); } /** * 显示分页 * @access public * @return string HTML分页字符串 */ public function pageShow(){ $this->uri(); if($this->pageToatl>1){ if($this->page == 1){ $first = ''.$this->pageShow['first'].''; $up = ''.$this->pageShow['up'].''; }else{ $first = 'uri.'&'.$this->pageParam.'=1">'.$this->pageShow['first'].''; $up = 'uri.'&'.$this->pageParam.'='.($this->page-1).'">'.$this->pageShow['up'].''; } if($this->page >= $this->pageToatl){ $ending = ''.$this->pageShow['ending'].''; $down = ''.$this->pageShow['down'].''; }else{ $ending = 'uri.'&'.$this->pageParam.'='.$this->pageToatl.'">'.$this->pageShow['ending'].''; $down = 'uri.'&'.$this->pageParam.'='.($this->page+1).'">'.$this->pageShow['down'].''; } $input = ''; $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); } /** * 数字分页 */ private function 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 - $number<0?$this->page - $number-1:0; if($this->page+$number-$DStart > $this->pageToatl){ $DStop = ($this->page+$number-$DStart) - $this->pageToatl; $forStop = $this->pageToatl+1; }else{ $DStop = 0; $forStop = $this->page+$number-$DStart+1; } $forStart = $this->page-$number-$DStop<1?1:$this->page-$number-$DStop; for($i=$forStart;$i<$forStop;++$i){ if($i==$this->page){ $numberF .= ''.$i.''; }else{ $numberF .= 'uri.'&'.$this->pageParam.'='.$i.'">'.$i.''; } } } if($pageD!==false){ $number = $this->pageNumber; $forStart = $this->page-$number>0?$this->page-$number:1; $forStop = $this->page+$number>$this->pageToatl?$this->pageToatl+1:$this->page+$number+1; for($i=$forStart;$i<$this->page;++$i){ $numberD .= 'uri.'&'.$this->pageParam.'='.$i.'">'.$i.''; } $numberD .= ''.$this->page.''; $start = $this->page+1; for($i=$start;$i<$forStop;++$i){ $numberD .= 'uri.'&'.$this->pageParam.'='.$i.'">'.$i.''; } } $F = $forStart>1?'uri.'&'.$this->pageParam.'=1">1':''; $E = $forStop<$this->pageToatl+1?'uri.'&'.$this->pageParam.'='.$this->pageToatl.'">'.$this->pageToatl.'':''; if($forStart>2){ $omitF = '…'; $startA = $this->page-$number<1?1:$this->page-$number; $omitFA = 'uri.'&'.$this->pageParam.'='.$startA.'">…'; } if($forStop<$this->pageToatl){ $omitE = '…'; $stopA = $this->page+$number>$this->pageToatl?$this->pageToatl:$this->page+$number; $omitEA = 'uri.'&'.$this->pageParam.'='.$stopA.'">…'; } } $this->pageType = str_ireplace(array('%F%','%E%','%omitFA%','%omitEA%','%omitF%','%omitE%','%numberF%','%numberD%'),array($F,$E,$omitFA,$omitEA,$omitF,$omitE,$numberF,$numberD),$this->pageType); } /** * 处理url的方法 * @access public * @param array $url 保持URL直对关系数组 * @return string 过滤后的url尾参数 */ private function 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方法及计算起始条数和结束条数 */ private function 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->total?$this->total:$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; default: return; } }}
分页类有问题。你可以用这个试试。
第%page%页/共%pageToatl%页%first%%up%%F%%omitFA%%numberF%%omitEA%%E%%down%%ending%'; //显示值设置 private $pageShow = array('first'=>'首页','ending'=>'尾页','up'=>'上一页','down'=>'下一页','GoTo'=>'GO'); /** * 初始化数据,构造方法 * @access public * @param int $total 数据总数量 * @param int $pageSize 每页显示条数 * @param int $pageNumber 分页数字显示数量(使用%numberF%和使用%numberD%会有不同的效果) * @param string $pageParam 分页变量 * @return void */ public function __construct($total,$pageSize=10,$pageNumber=5,$pageParam='p'){ $this->total = $total<0?0:$total; $this->pageSize = $pageSize<0?0:$pageSize; $this->pageNumber = $pageNumber<0?0:$pageNumber; $this->pageParam = $pageParam; $this->calculate(); } /** * 显示分页 * @access public * @return string HTML分页字符串 */ public function pageShow(){ $this->uri(); if($this->pageToatl>1){ if($this->page == 1){ $first = ''.$this->pageShow['first'].''; $up = ''.$this->pageShow['up'].''; }else{ $first = 'uri.'&'.$this->pageParam.'=1">'.$this->pageShow['first'].''; $up = 'uri.'&'.$this->pageParam.'='.($this->page-1).'">'.$this->pageShow['up'].''; } if($this->page >= $this->pageToatl){ $ending = ''.$this->pageShow['ending'].''; $down = ''.$this->pageShow['down'].''; }else{ $ending = 'uri.'&'.$this->pageParam.'='.$this->pageToatl.'">'.$this->pageShow['ending'].''; $down = 'uri.'&'.$this->pageParam.'='.($this->page+1).'">'.$this->pageShow['down'].''; } $input = ''; $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); } /** * 数字分页 */ private function 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 - $number<0?$this->page - $number-1:0; if($this->page+$number-$DStart > $this->pageToatl){ $DStop = ($this->page+$number-$DStart) - $this->pageToatl; $forStop = $this->pageToatl+1; }else{ $DStop = 0; $forStop = $this->page+$number-$DStart+1; } $forStart = $this->page-$number-$DStop<1?1:$this->page-$number-$DStop; for($i=$forStart;$i<$forStop;++$i){ if($i==$this->page){ $numberF .= ''.$i.''; }else{ $numberF .= 'uri.'&'.$this->pageParam.'='.$i.'">'.$i.''; } } } if($pageD!==false){ $number = $this->pageNumber; $forStart = $this->page-$number>0?$this->page-$number:1; $forStop = $this->page+$number>$this->pageToatl?$this->pageToatl+1:$this->page+$number+1; for($i=$forStart;$i<$this->page;++$i){ $numberD .= 'uri.'&'.$this->pageParam.'='.$i.'">'.$i.''; } $numberD .= ''.$this->page.''; $start = $this->page+1; for($i=$start;$i<$forStop;++$i){ $numberD .= 'uri.'&'.$this->pageParam.'='.$i.'">'.$i.''; } } $F = $forStart>1?'uri.'&'.$this->pageParam.'=1">1':''; $E = $forStop<$this->pageToatl+1?'uri.'&'.$this->pageParam.'='.$this->pageToatl.'">'.$this->pageToatl.'':''; if($forStart>2){ $omitF = '…'; $startA = $this->page-$number<1?1:$this->page-$number; $omitFA = 'uri.'&'.$this->pageParam.'='.$startA.'">…'; } if($forStop<$this->pageToatl){ $omitE = '…'; $stopA = $this->page+$number>$this->pageToatl?$this->pageToatl:$this->page+$number; $omitEA = 'uri.'&'.$this->pageParam.'='.$stopA.'">…'; } } $this->pageType = str_ireplace(array('%F%','%E%','%omitFA%','%omitEA%','%omitF%','%omitE%','%numberF%','%numberD%'),array($F,$E,$omitFA,$omitEA,$omitF,$omitE,$numberF,$numberD),$this->pageType); } /** * 处理url的方法 * @access public * @param array $url 保持URL直对关系数组 * @return string 过滤后的url尾参数 */ private function 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方法及计算起始条数和结束条数 */ private function 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->total?$this->total:$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; default: return; } }}