ZF-9260: Paginator (NULL adapter) fails when number of items is 0.
Description
When using Zend_Paginator I ran into a problem since the 1.10.x versions.
In some 1.9.x code I'm using something like this:
// $total is set some where in the code, could be some query result.
// After some code, we get the following 'settings'.
$total = 0;
$page = 1;
$itemsPerPage = 5;
// Create paginator with null adapter.
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Null($total));
$paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage($itemsPerPage);
// Get in in view.
$this->view->paginator = $paginator;
Works fine in 1.9.x, in 1.10.x I get an error because of some array error.
In the NULL adapter, the getItems() function was changed.
I think the 'problem' could be solved by adding a check for 0 items. In the current code (1.10.2), there is only a check for "$offset > $this->count()". When the count = 0, it should also return an empty array:
public function getItems($offset, $itemCountPerPage)
{
if ($this->count() == 0 || $offset > $this->count()) {
return array();
}
$remainItemCount = $this->count() - $offset;
$currentItemCount = $remainItemCount > $itemCountPerPage ? $itemCountPerPage : $remainItemCount;
return array_fill(0, $currentItemCount, null);
}
Comments
Posted by Ramon Henrique Ornelas (ramon) on 2010-02-25T04:51:39.000+0000
This problem has been fixed in 1.10.2
See http://framework.zend.com/code/changelog/….
Try a simple test
Posted by Matthew Weier O'Phinney (matthew) on 2010-02-25T04:56:26.000+0000
Sven, you indicate the issue also affects 1.10.2, but did you actually test against 1.10.2? As noted, this sounds like the same issue as reported in ZF-4151, which has already been resolved. Please let us know if this is not the case.
Posted by Sven Franke (snef) on 2010-02-25T05:29:12.000+0000
Ramon, Matthew...
I am so terribly sorry! Something went wrong with the svn-update of the Zend-lib, so it was not updated correctly :(
I was sure I was using 1.10.2, but in fact it still was 1.10.1!
I will go stand in some corner of the room for the rest of the day. Shame on me!