Wednesday, September 2, 2009

PAGINATING CONTENT ITEMS

I just ran into an issue that will likely come up many times; how to paginate model result sets. Zend Framework has the Zend_Paginator component, but the closest adapter to use would be the DbTableSelect adapter, which returns a Zend_Db_Table_ResultSet.

I could have made this work, but decided to try and  write a Zend_Paginator adapter. It turns out (at least in this case) it was incredibly simple.
  1. I copied the DbTableSelect adapter, which only has one method, get items.
  2. I updated the constructor to take a Dig_Model rather than a select object. It sets the model, and then passes the model's select object down to the parent Zend_Paginator_Adapter_DbSelect class.
  3. I updated the getItems method, so it uses the model's fetchAll() method, rather than the Zend_Db_Select fetchAll() method.

No comments:

Post a Comment