ZF-3873: Zend_Paginator sets an incorrect lastItemNumber when using the Null adapter.

Issue Type: Bug Created: 2008-08-06T11:57:46.000+0000 Last Updated: 2009-07-29T08:07:50.000+0000 Status: Resolved Fix version(s): - 1.6.1 (15/Sep/08)

Reporter: Jim Safley (jimsafley) Assignee: Jurrien Stutterheim (norm2782) Tags: - Zend_Paginator

Related issues: Attachments:


When using Zend_Paginator_Adapter_Null, Zend_Paginator::_pages->lastItemNumber is set incorrectly. This is because Zend_Paginator_Adapter_Null::getItems() returns an empty array, which Zend_Paginator::getItemsByPage() casts to an empty ArrayIterator, which, in turn, sets Zend_Paginator::_pages->lastItemNumber to an incorrect number. Shouldn't Zend_Paginator_Adapter_Null::getItems() return an array containing the number of empty values equal to Zend_Paginator_Adapter_Null::_count ? Am I overlooking something?

Here's a patch:

Index: Paginator/Adapter/Null.php

--- Paginator/Adapter/Null.php (revision 10727) +++ Paginator/Adapter/Null.php (working copy) @@ -58,7 +58,7 @@ */ public function getItems($offset, $itemCountPerPage) { - return array(); + return array_slice(array_fill(0, $this->_count, ''), $offset, $itemCountPerPage); }



Posted by Matthew Ratzloff (mratzloff) on 2008-08-07T20:16:06.000+0000

Thanks for the excellent bug report, Jim!

Fixed this in revisions 10791-10793.

Posted by Ken Chou (kenchou77) on 2009-05-31T09:28:46.000+0000

sorry, the bug still here.

return array_slice(array_fill(0, $this->_count, ''), $offset, $itemCountPerPage); work fine. or better way to do it: public function getItems($offset, $itemCountPerPage) { $remainItemCount = $this->_count > $offset ? $this->_count - $offset : 0; $currentItemCount = $remainItemCount > $itemCountPerPage ? $itemCountPerPage : $remainItemCount; return array_fill(0, $currentItemCount, null); }

Test code:

$paginator = Zend_Paginator::factory(2); $paginator->setCurrentPageNumber(1); $paginator->setItemCountPerPage(5);

$pages = $paginator->getPages();


--- except result --- ["currentItemCount"] => int(2) ["lastItemNumber"] => int(2)

--- actual result --- ["currentItemCount"] => int(5) ["lastItemNumber"] => int(5)

Posted by Ken Chou (kenchou77) on 2009-05-31T20:40:30.000+0000

array_fill cannot accept zeor:

    if ($this->_count <= $offset) return array();
    $remainItemCount = $this->_count - $offset;
    $currentItemCount = $remainItemCount > $itemCountPerPage ? $itemCountPerPage : $remainItemCount;
    return array_fill(0, $currentItemCount, null);

Posted by Jurrien Stutterheim (norm2782) on 2009-07-29T08:07:48.000+0000

Resolved in r17281

Have you found an issue?

See the Overview section for more details.


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

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