Zend分页,链接和点之间的数量有限 [英] Zend pagination with limited number of links and dots between

查看:74
本文介绍了Zend分页,链接和点之间的数量有限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了Zend分页,但是不知道如何限制分页中的链接数量.我知道setPageRange,但这不是我想要的.

I have implemented a Zend Pagination but can't figure out how to limit the number of links in the pagination. I know about setPageRange, but it isn't exactly what i want.

当前分页看起来像这样.

Currently the pagination looks like this.

< | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | >

但是我想要的是这样的:

But what i want is something like this:

第1页

< | 1 | 2 | 3 | ... | 14 | 15 | 16 | >

第8页

< | 1 | 2 | 3 | ... | 7 | 8 | 9 | ... | 14 | 15 | 16 | >

第14页

< | 1 | 2 | 3 | ... | 13 | 14 | 15 | 16 | >

推荐答案

在这里,我可以为您提供在我的一个应用程序中实现的分页助手脚本,该脚本与您想要的上述脚本相同.

here i can give you pagination helper script which i have implemented in one of my application and it is same like as above you want.

<?php

 if ($this->pageCount) :
 $midRange = floor(sizeof($this->pagesInRange) / 2);
 if (($this->current + $midRange) < $this->pageCount && $this->pageCount > 5) : 
    array_pop($this->pagesInRange); 
 $display_end = true;
 endif; 

 ?>
<div class="paginationControl<?php echo  $this->position; ?>">

 <div class="paginationControl_pages">
 <!-- Previous page link -->

 <?php if (isset($this->previous)): ?>
 <?php if($this->extraVar != "" ){ ?>
            <a href="<?php echo  $this->url(array_merge($this->extraVar,array('page' => $this->previous))). $this->query; ?>" class="paging-active">&nbsp;Previous&nbsp;</a> &nbsp;
 <?php }else {?>
            <a href="<?php echo  $this->url(array('page' => $this->previous)). $this->query; ?>" class="paging-active">&nbsp;Previous&nbsp;</a> &nbsp;
 <?php }?>
 <?php else: ?>
 <span class="paging-active"><strong>&nbsp;Previous&nbsp;</strong></span>&nbsp;
 <?php endif; ?>
 <span ><?php if (($this->current - $midRange) > $this->first && $this->pageCount > 5): ?></span>
 <?php  
 array_shift($this->pagesInRange);?>

 <?php if($this->extraVar != "" ){ ?>
  <a href="<?php echo $this->url(array_merge($this->extraVar,array('page' => $this->first))) . $this->query; ?>" ><span class="paging"><?php echo $this->first ?></span></a>...
 <?php } else {?> 
 <a href="<?php echo $this->url(array('page' => $this->first)) . $this->query; ?>" ><span class="paging"><?php echo $this->first ?></span></a>...
 <?php }?>

 <?php endif; ?>
 <!-- Numbered page links -->
 <?php foreach ($this->pagesInRange as $page): ?>

 <?php if ($page != $this->current): ?>

 <?php if($this->extraVar != "" ){ ?>
            <a href="<?php echo $this->url(array_merge($this->extraVar,array('page'=>$page))); ?>""><span class="paging"><?php echo $page; ?></span></a>
        <?php }else{ ?>  
            <a href="<?php echo $this->url(array('page'=>$page)); ?>"><span class="paging"><?php echo $page; ?></span></a>
        <?php } ?>

 <?php else: ?>

        <span class="paging-active"><strong><?php echo $page; ?>&nbsp;&nbsp;</strong></span>
 <?php endif; ?>
 <?php endforeach; ?>
 <?php if (!empty($display_end)) : 
 ?>
 <?php if($this->extraVar != "" ){ ?>
 ...<a href="<?php echo $this->url(array_merge($this->extraVar,array('page' => $this->last))) . $this->query; ?>" ><span class="paging"><?php echo $this->last ?></span></a> 
 <?php }else{?>
 ...<a href="<?php echo $this->url(array('page' => $this->last)) . $this->query; ?>" ><span class="paging"><?php echo $this->last ?></span></a> 
 <?php }?>
 <?php endif; ?>
 <!-- Next page link -->
 <?php if (isset($this->next)): ?>
  <?php if($this->extraVar != "" ){ ?>
  &nbsp;<a href="<?php echo $this->url(array_merge($this->extraVar,array('page' => $this->next))) . $this->query; ?>" class="paging-active">&nbsp;Next&nbsp;</a>&nbsp;
  <?php }else{?>
 &nbsp;<a href="<?php echo $this->url(array('page' => $this->next)) . $this->query; ?>" class="paging-active">&nbsp;Next&nbsp;</a>&nbsp;
 <?php }?>
 <?php else: ?>
 &nbsp;<span class="paging-active"><strong>Next&nbsp;&nbsp;</strong></span>&nbsp;
 <?php endif; ?>
 </div>
</div>
<?php endif; ?>

希望这一定会帮助您获得理想的输出.

hope this will sure help you to get your desire OUTPUT.

这篇关于Zend分页,链接和点之间的数量有限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆