1
votes

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;
}
1
I'm not understanding this question. Where is the point of failure? $fileTable->getFilesByOfficeName($officeName, $page); can return false, have you ruled out that your paginator is being returned? - brady.vitrano
@brady.vitrano the paginator seems to be returned (i.e. not false), but when I attempt to click on any other page, the paginator goes away (the result set?) because the $_GET['officeName'] parameter seems to be needed. But I'm not sure how to keep providing it (i.e., the links in the paginator control don't provide the officeName value). - tjb1982

1 Answers

0
votes

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>