Zend_Paginator返回为对象 [英] Zend_Paginator return as objects
本文介绍了Zend_Paginator返回为对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Zend_Paginator以标准数组的形式返回结果,但是我需要使结果作为类的实例返回,我该怎么做?
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?
例如,我想要所有新闻文章,因此需要我的物品作为News_Model_Article的实例回来
For example, I want all news articles so would need my items to come back as an instance of News_Model_Article
推荐答案
您还可以创建自定义的zend分页器适配器,例如:
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;
}
}
按如下所示使用它:
$adapter = new Application_Paginator_Adapter();
$paginator = new Zend_Paginator($adapter);
这篇关于Zend_Paginator返回为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文