max_page = ceil($this->total/$this->limit);//总页数
$this->page = $this->page<1?1:$this->page;//纠正页码小于1
$this->page = $this->page>$this->max_page?$this->max_page:$this->page;//纠正输入大于总页数
}
public function num_page()//生成数字列码 12345...78910
{
$output = '';
if ($this->max_page > 1) {//如果最大页大于1
if ($this->max_page <= ($this->num_links)) {
$start = 1; //开始数字1
$end = $this->max_page; //结束数字为最大页码
} else {
$start = $this->page - floor($this->num_links / 2); //floor() 函数向下舍入为最接近的整数
$end = $this->page + floor($this->num_links / 2);
if ($start < 1) {
$end += abs($start) + 1;
$start = 1;
}
if ($end > $this->max_page) {
$start -= ($end - $this->max_page);
$end = $this->max_page;
}
}
if ($start > 1) {
$output .= '
...';
}
for ($i = $start; $i <= $end; $i++) {
if ($this->page == $i) {
$output .= '' . $i . '';
} else {
$output .= '' . $i . '';
}
}
if ($end < $this->max_page) {
$output .= '...';
}
}
return $output;
}
public function show($mode=1)//$mode 分页模版
{
$this->init();//初始化值
switch ($mode)
{
case 1:
$html = '
';
break;
case 2://缩减版分页数据
$html =array(
'0'=>$this->page>1?str_replace('{page}', $this->page - 1, $this->url):'#', //上一页连接
'1'=>$this->page>1?false:true, //上一页状态
'2'=>$this->page, //当前页
'3'=>$this->max_page, //总页数
'4'=>$this->page < $this->max_page?str_replace('{page}', $this->page + 1, $this->url):'#', //下一页状态
'5'=>$this->page < $this->max_page?false:true, //下一页状态
);
break;
default:
break;
}
return $html;
}
}
?>