Chinaunix首页 | 论坛 | 博客
  • 博客访问: 69637
  • 博文数量: 67
  • 博客积分: 1334
  • 博客等级: 中尉
  • 技术积分: 670
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-08 10:56
文章分类

全部博文(67)

文章存档

2016年(2)

2015年(2)

2012年(9)

2011年(54)

我的朋友
最近访客

分类: 系统运维

2011-12-21 16:50:11

  1. <?php
  2. /**
  3.  *
  4.  * 分页链接
  5.  * Enter description here ...
  6.  * @author maofeng
  7.  *
  8.  */
  9. class Mf_Helpers_Paginate extends Zend_Controller_Action_Helper_Abstract
  10. {
  11.     
  12.     public function __construct(){
  13.     
  14.     }
  15.     
  16.     /**
  17.      *
  18.      * Enter description here ...
  19.      * @param unknown_type $param
  20.      * @param unknown_type $other
  21.      */
  22.     public function number($param = array(), $other = array()){
  23.     
  24.         $result = '';
  25.         $search = '';
  26.         
  27.         $controller = isset($param['controller']) ? $param['controller'] : 'index';//控制器名称
  28.         $action = isset($param['action']) ? $param['action'] : 'index';//动作名称
  29.         $total = isset($param['total']) ? $param['total'] : 0;//总共有多少条数据
  30.         $current = isset($param['current']) ? $param['current'] : 1;//当前是第几页
  31.         $pageSize = isset($param['pageSize']) ? $param['pageSize'] : 20;//每页的条数
  32.         $showSize = isset($param['showSize']) ? $param['showSize'] : 10;//显示大小

  33.         if($total == 0){
  34.             return $result;
  35.         }
  36.         
  37.         if(!empty($other)){
  38.             foreach ($other as $k => $v){
  39.                 $search .= "/$k/$v";
  40.             }
  41.         }

  42.         //loop times
  43.         $loops = ceil($total / $pageSize);
  44.         
  45.         if($loops <= $showSize){
  46.             
  47.             $start = 1;
  48.             $end = $loops;
  49.             
  50.         }else{

  51.             $start = 1;
  52.             
  53.             $leftSize = ceil($showSize / 2);
  54.             
  55.             if( ($current - $leftSize) > 0 && ($current + $leftSize) <= $loops ){
  56.                 $start = $current - $leftSize;            
  57.             }
  58.             
  59.             if( ($current - $leftSize) < 0 ){
  60.                 $start = 1;
  61.             }
  62.             
  63.             if( ($current + $leftSize) > $loops ){
  64.                 $start = $loops - $showSize + 1;
  65.             }
  66.             
  67.             $end = $showSize + $start - 1;
  68.             
  69.         }
  70.         
  71.         $result = '.$controller.'/'.$action.'/page/1'.$search.'">首页';
  72.             
  73.         for($i=$start; $i<=$end; $i++){
  74.             
  75.             if($i != $current){
  76.                 $result .= '.$controller.'/'.$action.'/page/'.$i.$search.'">'.$i.'';
  77.             }else{
  78.                 $result .= ''.$i.'';
  79.             }
  80.         }
  81.         
  82.         $result .= '.$controller.'/'.$action.'/page/'.$loops.$search.'">尾页';
  83.         
  84.         
  85.         
  86.         return $result;
  87.     }
  88.     
  89.     
  90. }
阅读(1331) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~