Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend_Paginator return as objects

Zend_Paginator returns results as a standard array but I need to make my results come back as an instance of a class, how do I do this?

For example, I want all news articles so would need my items to come back as an instance of News_Model_Article

like image 601
Ashley Avatar asked Dec 16 '22 20:12

Ashley


1 Answers

You can also create custom zend paginator adapter like:

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 below:

$adapter = new Application_Paginator_Adapter();
$paginator = new Zend_Paginator($adapter);
like image 57
subosito Avatar answered Dec 31 '22 19:12

subosito