如何为大数据集设置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.

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

try this

    $select = $this->select()->where('id='.$id)
                             ->order('date DESC');

    $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
    $pageNumber = $this->_getParam('page');       
    $paginator->setCurrentPageNumber($pageNumber);
    $paginator->setItemCountPerPage(10);
    $this->view->data = $paginator;