Zend_Paginator 停止工作

发布于 2024-11-24 19:08:08 字数 1957 浏览 2 评论 0原文

我正在学习 Zend 框架。我让 Zend_Paginator 使用数组适配器,但我在使用 Zend_Paginator::factory 静态方法时遇到问题。问题是分页控制链接将我发送到正确的 URL,但当我单击下一页或第 2、3 页等时,结果消失。

我有数据库中的两个表:文件表和 origination_office 表。文件表包含客户的姓名、地址等,始发办公室存储办公室名称(如坦帕、萨拉索塔等)。每个文件都与一个起源办公室相关联。

我的控制器:

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

这是 getFilesByOfficeName() 方法:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

源来凯始玺欢你 2024-12-01 19:08:08

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

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

我需要看看您在部分中做了什么才能给出准确的答案,但如果您将 ?$_SERVER['QUERY_STRING'] 添加到最终网址的末尾,这应该可以工作。请参阅下面的示例:

<!-- 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 »</a>

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 »</a>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文