dou4064 2013-05-17 03:17 采纳率: 100%
浏览 81
已采纳

如何为大数据集设置zend分页?

I want to set pagination for large collection of data set say tens of thousands. If you fetch all data at once performance will be slow. So I need a better approach:

In my controller I have the code as given:

    $result = $result = $this->fetchAll($this->select()
                                            ->where('id='.$id)
                                            ->order('date DESC'))->toArray();
    $paginator = Zend_Paginator::factory($data);
    $pageNumber = $this->_getParam('page');       
    $paginator->setCurrentPageNumber($pageNumber);
    $paginator->setItemCountPerPage(10);
    $this->view->data = $paginator;

This code will fetch all database contents at once.

  • 写回答

2条回答 默认 最新

  • douhua1890 2013-05-17 03:31
    关注

    Try this:

    $select = new Zend_Paginator_Adapter_DbSelect($sql);
    $select->count($select);
    $paginator = new Zend_Paginator($select);
    

    You can get more details from here:

    Paginating data collection

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部