1

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;
}
4

1 回答 1

0

好的,我想我理解你的问题。您的链接没有维护您的初始请求状态及其 URL 查询字符串。

您可能想要编辑部分视图 ( _pagination_control.phtml) 以在链接中呈现当前查询字符串。

我需要查看您在部分中所做的事情才能给出确切的答案,但是如果您添加 ?$_SERVER['QUERY_STRING']到最终 URL 的末尾,这应该可以工作。请参见下面的示例:

<!-- 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>
于 2011-07-18T21:46:24.263 回答