3

使用 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"

已编辑

<!--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;
4

3 回答 3

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; ?>
于 2012-02-09T11:55:14.733 回答
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;

您可以在Zend Paginator 的配置方法中找到更多信息

于 2012-02-09T10:01:39.573 回答
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; ?>
于 2012-02-27T13:35:10.600 回答