//本分页类不处理SQL; //大大的加快了分页功能 //http://blog.csdn.net/fkedwgwy //潇湘博客--潇湘 /** 演示 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); echo '开始AJAX模式:'; $ajaxpage=new page(array('total'=>1000,'perpage'=>20,'ajax'=>'ajax_page','page_name'=>'test')); echo 'mode:1 '.$ajaxpage->show(); */ class Zend_Page { /** * config ,public */ var $page_name="page";//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分页模式 var $next_ten_page=">>>"; var $per_ten_page="<<<";
/** * private * */ var $pagebarnum=10;//控制记录条的个数。 var $totalpage=0;//总页数 var $ajax_action_name='';//AJAX动作名 var $nowindex=1;//当前页 var $url="";//url地址头 var $offset=0; var $total='';
/** * constructor构造函数 * * @param array $array['total'],$array['perpage'],$array['nowindex'],$array['url'],$array['ajax']... */ function Zend_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))||($total<0))$this->error(__FUNCTION__,$total.' is not a positive integer!'); if((!is_int($perpage))||($perpage<=0))$this->error(__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->total=$total; $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!"); }