简体   繁体   中英

How to limit the number of pagination links in Zend_Paginator

When using Zend_Paginator, I don't want it to show me all the pagination links. Here's how I am implementing it:

  $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;

Now it is showing me all the links. Eg there are 100 records and 10 rows per page, so it will show me 1 to 10 links. How can I have 5 links, 1 to 5? Like this:

"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; ?>

How can I change it so that it shows me only 5 links?

$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;

$paginator->setPageRange(5); works for me. However you may need to apply this feature in your paginator control.
This is what the page link section of my control looks like.

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

this is a good one. By default, Zend Paginator sets the default to 10 as you've seen. But the way to override it is as follows:

$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;

You can find a bit more information in the configuration methods for Zend Paginator

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM