使用Zend_Paginator时,我不希望它向我显示所有分页链接。这是我实现它的方式:
$adapter = new Zend_Paginator_Adapter_DbSelect($result);
$paginator = new Zend_Paginator($adapter);
$page=$this->_getParam('page',1);
$paginator->setItemCountPerPage(10);
$paginator->setCurrentPageNumber($page);
$this->view->paginator=$paginator;
现在它正在显示所有链接。例如。每页有100条记录和10行,因此它将显示1到10个链接。 我如何拥有5个链接,1到5个? 像这样:
"start" "previous" 1 2 3 4 5 "Next" "End"
EDITED
<!--Number page links-->
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<a href="<?= $this->url(array('page' => $page)); ?>">
<span class="fg-button ui-button ui-state-default"><?= $page; ?></span>
</a>
<?php else: ?>
<span class="fg-button ui-button ui-state-default ui-state-disabled" ><?= $page; ?></span>
<?php endif; ?>
<?php endforeach; ?>
如何更改它以便它只显示5个链接?
$adapter = new Zend_Paginator_Adapter_DbSelect($select);
$paginator = new Zend_Paginator($adapter);
$page=$this->_getParam('page',1);
$paginator->setItemCountPerPage(10);
$paginator->setCurrentPageNumber($page);
$paginator->setPageRange(5);
$this->view->paginator=$paginator;
答案 0 :(得分:2)
$paginator->setPageRange(5);
适合我。但是,您可能需要在分页器控件中应用此功能
这就是我的控件的页面链接部分。
<!--Number page links-->
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current) : ?>
<a href="<?php echo $this->url(array_merge($params,
array('page' => $page))) ?>">
<?php echo $page ?></a> |
<?php else: ?>
<?php echo $page ?> |
<?php endif; endforeach; ?>
答案 1 :(得分:0)
这是一个很好的。默认情况下,Zend Paginator将默认值设置为10,如您所见。但覆盖它的方法如下:
$adapter = new Zend_Paginator_Adapter_DbSelect($result);
$paginator = new Zend_Paginator($adapter);
$page=$this->_getParam('page',1);
$paginator->setItemCountPerPage(10);
$paginator->setCurrentPageNumber($page);
$paginator->setPageRange(5);
$this->view->paginator=$paginator;
中找到更多信息
答案 2 :(得分:0)
<!-- Numbered page links -->
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<?php if ($page <6): ?>
<a href="<?= $this->url(array('page' => $page)); ?>"><span class="fg-button ui-button ui-state-default"><?= $page; ?></span></a>
<?php elseif($page <6): ?>
<span class="fg-button ui-button ui-state-default ui-state-disabled" ><?= $page; ?></span>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>