Search code examples
zend-frameworkzend-paginator

Zend_Paginator stopped working


I'm learning Zend Framework. I had Zend_Paginator working with the array adapter, but I'm having trouble using the Zend_Paginator::factory static method. The problem is the pagination control links send me to the correct URL, but the results disappear when I click next or page 2, 3, etc.

I have two tables from a database: a file table and an origination_office table. The file table has the client's names, address, etc. and the origination office stores office names (like Tampa, Sarasota, etc.). Each file is associated with an origination office.

My controller:

public function searchAction()
{

    $searchForm = new Application_Form_SearchForm();
    if ($this->_request->getQuery()) {
        if ($searchForm->isValid($this->_request->getParams())) {
            $officeName = $this->_request->getParam('officeName');
            $page = $this->_request->getParam('page');
        }
        $fileTable = new Application_Model_DbTable_File();
        $this->view->paginator = $fileTable->getFilesByOfficeName($officeName, $page);

    }
    $this->view->searchForm = $searchForm;
}

Here is the getFilesByOfficeName() method:

public function getFilesByOfficeName($officeName = null, $page = 1, $count = 12, $range = 15, $scrolling = 'Sliding') 
{
    if (is_null($officeName)) {
        $query = $this->select();
        $paginator = Zend_Paginator::factory($query);
    } else {
        $oofTable = new Application_Model_DbTable_OriginationOffice();
        $query = $oofTable->select();
        $query->where('oof_name like ?', $officeName.'%');
        if ($oofTable->fetchRow($query)) {
            $origination_office = $oofTable->fetchRow($query);
            $files = $origination_office->findDependentRowset($this);
            $paginator = Zend_Paginator::factory($files);
        } else {
            return;
        }
    }
    Zend_Paginator::setDefaultScrollingStyle($scrolling);
    Zend_View_Helper_PaginationControl::setDefaultViewPartial('_pagination_control.phtml');
    $paginator->setDefaultItemCountPerPage($count);
    $paginator->setDefaultPageRange($range);
    $paginator->setCurrentPageNumber($page);
    return $paginator;
}

Solution

  • Ok, I think I am understanding your problem. Your links are not maintaining the state of your initial request and it's URL query string.

    You might want to edit your partial view (_pagination_control.phtml) to render the current query string in your links.

    I would need to see what your doing in the partial to give an exact answer, but this should work if you add ?$_SERVER['QUERY_STRING'] to the end of your final URL. See Below Example:

    <!-- Your href may look different but notice I append the query string to the end -->
    <a href="<?php echo $this->url(array('page' => $this->last)); ?>?<?php echo $_SERVER['QUERY_STRING'];?>">Last &raquo;</a>