/** * filename: ext_page.class.php * @package:phpbean * @author :feifengxlq * @copyright :Copyright 2006 feifengxlq * @license:version 2.0 * @create:2006-5-31 * @modify:2006-6-1 * @modify:feifengxlq 2006-11-4 * description:超强分页类,四种分页模式,默认采用类似baidu,google的分页风格。 * 2.0增加功能:支持自定义风格,自定义样式,同时支持PHP4和PHP5, * to see detail,please visit http://www.phprm.com * example: * 模式四种分页模式: require_once('../libs/classes/page.class.php'); $page=new page(array('total'=>1000,'perpage'=>20)); echo 'mode:1 '.$page->show(); echo 'mode:2 '.$page->show(2); echo 'mode:3 '.$page->show(3); echo 'mode:4 '.$page->show(4); 开启AJAX: $ajaxpage=new page(array('total'=>1000,'perpage'=>20,'ajax'=>'ajax_page','page_name'=>'test')); echo 'mode:1 '.$ajaxpage->show(); 采用继承自定义分页显示模式: demo:[url=http://www.phpobject.net/blog]http://www.phpobject.net/blog[/url] */ class Page { /** * config ,public */ var $page_name="p";//page标签,用来控制url页。比如说xxx.php?PB_page=2中的PB_page var $next_page='>';//下一页 var $pre_page=' var $first_page='First';//首页 var $last_page='Last';//尾页 var $pre_bar=' var $next_bar='>>';//下一分页条 var $format_left=''; var $format_right=''; var $is_ajax=false;//是否支持AJAX分页模式
/** * private * */ var $pagebarnum=10;//控制记录条的个数。 var $totalpage=0;//总页数 var $ajax_action_name='';//AJAX动作名 var $nowindex=1;//当前页 var http://pic3.phprm.com/2013/06/08/$url="".jpg;//url地址头 var $offset=0;
/** * constructor构造函数 * * @param array $array['total'],$array['perpage'],$array['nowindex'],$array['url'],$array['ajax']... */ function page($array) { if(is_array($array)){ //if(!array_key_exists('total',$array))$this->error(__FUNCTION__,'need a param of total'); $total=intval($array['total']); $perpage=(array_key_exists('perpage',$array))?intval($array['perpage']):10; $nowindex=(array_key_exists('nowindex',$array))?intval($array['nowindex']):''; $url=(array_key_exists('url',$array))?$array['url']:''; }else{ $total=$array; $perpage=10; $nowindex=''; $url=''; } //if((!is_int($total))||($totalerror(__FUNCTION__,$total.' is not a positive integer!'); if((!is_int($perpage))||($perpageerror(__FUNCTION__,$perpage.' is not a positive integer!'); if(!empty($array['page_name']))$this->set('page_name',$array['page_name']);//设置pagename $this->_set_nowindex($nowindex);//设置当前页 $this->_set_url($url);//设置链接地址 $this->totalpage=ceil($total/$perpage); $this->offset=($this->nowindex-1)*$perpage; if(!empty($array['ajax']))$this->open_ajax($array['ajax']);//打开AJAX模式 } /** * 设定类中指定变量名的值,如果改变量不属于这个类,将throw一个exception * * @param string $var * @param string $value */ function set($var,$value) { if(in_array($var,get_object_vars($this))) $this->$var=$value; else { $this->error(__FUNCTION__,$var." does not belong to PB_Page!"); }
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn