ZF-3873: Zend_Paginator sets an incorrect lastItemNumber when using the Null adapter.
Description
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); }
/**
Comments
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();
Zend_Debug::dump($pages);
--- 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:
Posted by Jurrien Stutterheim (norm2782) on 2009-07-29T08:07:48.000+0000
Resolved in r17281