ZF-8072: Add getItemsByPageRange function

Issue Type: Improvement Created: 2009-10-14T09:22:07.000+0000 Last Updated: 2012-11-20T20:53:30.000+0000 Status: Closed Fix version(s): Reporter: Nicholas Calugar (njcalugar) Assignee: None Tags: - Zend_Paginator

Related issues: Attachments:


My use case for this function is I was displaying a large dataset on a page using Zend_Paginator, but wanted the capability to export a page range as CSV. Here is the class I wrote that extends Zend_Paginator:

<pre class="highlight">
class My_Paginator extends Zend_Paginator
     * Returns the items for a given page range.
     * @return Traversable
    public function getItemsByPageRange($startPageNumber, $endPageNumber)
        $startPageNumber = $this->normalizePageNumber($startPageNumber);
        $endPageNumber = $this->normalizePageNumber($endPageNumber);
        if ($startPageNumber >= $endPageNumber) {
            return $this->getItemsByPage($startPageNumber);
    $offset = ($startPageNumber - 1) * $this->_itemCountPerPage;
    $itemCountPerPage = (($endPageNumber + 1) - $startPageNumber) * $this->_itemCountPerPage;
        $items = $this->_adapter->getItems($offset, $itemCountPerPage);

        $chunks = array_chunk($items, $this->_itemCountPerPage);
        for ($i=$startPageNumber; $i<$endPageNumber; $i++) {
            $chunk = each($chunks);
            if (!$chunk instanceof Traversable) {
                $chunk = new ArrayIterator($chunk);
            $this->_pageItems[$i] = $chunk;
        if (!$items instanceof Traversable) {
            $items = new ArrayIterator($items);
        return $items;


Posted by Rob Allen (rob) on 2012-11-20T20:53:30.000+0000

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.