Zend_Paginator and Zend_Paginator_Adapter_Null

I have been playing around with Zend_Paginator a little more, and came across a use case where I didn’t want the Paginator to manage the data, i.e. I was feeling lazy and didn’t feel like writing a custom adapter. You can use Zend_Paginator_Adapter_Null to manage the pagination controls and simply pass in the total number of results into the constructor. I.e


<?php
$paginator 
= new Zend_Paginator(new Zend_Paginator_Adapter_Null(‘43′));
$paginator->setCurrentPageNumber(‘1′);
$paginator->setItemCountPerPage(‘20′);
$this->view->paginator $paginator;

?>


The 43 I am passing into the constructor is the total number of results, and would likelu not be a static number, but coming from some other data source. For example, if you were using Zend_Service Flickr, it would look like this, assuming the variable $flickr has already been set up:


<?php
$paginator 
= new Zend_Paginator(new Zend_Paginator_Adapter_Null($flickr->totalResultsAvailable));
$paginator->setCurrentPageNumber(‘1′);
$paginator->setItemCountPerPage(‘20′);
$this->view->paginator $paginator;

?>


Follow the manual on setting up the actual display of the pagination. Now I need to get some more spare time and write a custom adapter for flickr and other Zend Services and also familiarize myself with caching of the paginator.

Leave a Reply