Updating the fetchBugs Method to Return a ZendPaginator Adapter

The fetchBugs() method that you wrote earlier creates a Zend_Db_Table_Select object, runs the fetchAll() method, and then returns the results. Things work a little differently with the paginator; since Zend_Paginator runs its own queries, you need to update the fetchBugs() method to return an instance of the DbTableSelect adapter. One other thing—since the method is no longer returning bugs, you should rename the method to fetchPaginatorAdapter(). I always like to name a method so it describes what the method will do and what it will return, as shown in Listing 4-21.

Listing4-21. The Updated and Renamed fetchBugs() Method in application/models/Bug.php public function fetchPaginatorAdapter($filters = array(), $sortField = null) {

$select = $this->select(); // add any filters which are set if(count($filters) > 0) {

foreach ($filters as $field => $filter) { $select->where($field . ' = ?', $filter);

// add the sort field is it is set if(null != $sortField) {

$select->order($sortField);

// create a new instance of the paginator adapter and return it $adapter = new Zend_Paginator_Adapter_DbTableSelect($select); return $adapter;

0 0

Post a comment

  • Receive news updates via email from this site