Zend_Paginator returns objects

Zend_Paginator returns the results as a standard array, but I need my results to be returned as an instance of the class, how to do this?

For example, I want all news articles to need my items returned as an instance of News_Model_Article

+4
source share
3 answers

You can also create your own paginator zend adapter, for example:

class Application_Paginator_Adapter extends Zend_Paginator_Adapter_DbSelect { public function getItems($offset, $itemCountPerPage) { $this->_select->limit($itemCountPerPage, $offset); $rowset = $this->_select->getTable()->fetchAll($this->_select); $articleModels = array(); foreach($rowset as $row) { $model = new News_Model_Article(); $model->setTitle($row->article_title); ........... $articleModels[] = $model; } return $articleModels; } } 

Use it as shown below:

 $adapter = new Application_Paginator_Adapter(); $paginator = new Zend_Paginator($adapter); 
+6
source

Use the Dag_Table Paginator, you can initiate it as follows:

 $table = new Your_Zend_DbTable(); // Asuming this has configured the $rowClass property $paginator = Zend_Paginator::factory($table->select()); $paginator->setItemCountPerPage(10); $paginator->setCurrentPageNumber(1); 

Then you can encode the $ paginator object and read the properties of the object.

+5
source

This may be a new feature, but if you use Zend_Paginator_Adapter_DbTableSelect , you should get the objects ( Zend_Db_Table_Row ) already.

+1
source

All Articles