1

我正在使用一项服务,它一次性获取过滤器的结果和结果总数。详细说明,假设总共有 100,000 条记录,我在一页上显示 25 条记录。我有一个数组:

$myarr = array('totalCount' => 100000,
      'results'       => array(...data...));

此数据一次限制为 25 条记录。

问题:当将此数据发送到 zend_paginator 时,它仅显示 1 页(锚点)与 prev[disabled] 和 next[disabled]。根据代码,它工作正常,但如何显示其他分页锚 [2,3,4,5,6,7,8,9] 等,因为我知道数据的总数。

我为此研究了很长时间,但是每个解决方案都是针对 DB 查询的,我没有从 DB 得到这个结果,它来自一个服务,导致 XML 格式被转换为一个数组。

$paginator      = new Zend_Paginator(new Zend_Paginator_Adapter_Array($myarr ['results']));
    $paginator->setItemCountPerPage(25);
    $paginator->setPageRange(10);
    $paginator->setCurrentPageNumber(1);

我如何发送总计数以便它在不加载所有数据的情况下创建其他分页链接,因为我收到了内存耗尽致命错误,因为加载了 100,000 条记录,而且每次获取所有记录的方式看起来也未优化,仅显示 25 条记录每个服务请求中的 TOTAL COUNT。

分页.phtml:

<div class="pagination" >
    <!-- Previous page link -->
    <?php if (isset($this->previous)): ?>
          <a href="javascript:void(0)" onclick='fetchPaginationData("<?php echo $this->divid;?>","<?php echo  $this->url(array('page' => $this->firstPageInRange -1)); ?>")'><span style="border-bottom-left-radius: 4px; border-left-width: 1px; border-top-left-radius: 4px;">Prev</span></a> 
    <?php else: ?>
        <span class="disabled" style="border-bottom-left-radius: 4px; border-left-width: 1px; border-top-left-radius: 4px;">Prev</span>
    <?php endif; ?>
    <!-- Numbered page links -->
    <?php foreach ($this->pagesInRange as $page): ?>
        <?php if ($page != $this->current): ?>
            <a href="javascript:void(0);" onclick='fetchPaginationData("<?php echo $this->divid;?>","<?php echo  $this->url(array('page' => $page)); ?>")' ><span><?php echo  $page; ?></span></a>
        <?php else: ?>
            <span class="page_current"><?php echo  $page; ?></span>
        <?php endif; ?>
    <?php endforeach; ?>
    <!-- Next page link -->
    <?php if (isset($this->next)): ?>
           <a href="javascript:void(0);" onclick='fetchPaginationData("<?php echo $this->divid;?>","<?php echo  $this->url(array('page' => $this->lastPageInRange +1)); ?>")'><span>Next &gt;</span></a> 
    <?php else: ?>
         <span class="disabled" style="border-bottom-right-radius: 4px; border-top-right-radius: 4px;">Next</span> 
    <?php endif; ?>

4

1 回答 1

1

唉,得到了zendy解决方案:D

        $this->view->results = $myarr['results'];   // actual data used for generation of rows
        $this->view->totalCount = $myarr['totalCount'];   // needed to show count on view     
        $resultMY = new Zend_Paginator_Adapter_Null($myarr['totalCount']);
        $paginator = new Zend_Paginator($resultMY);
        $paginator->setItemCountPerPage(25);
        $paginator->setPageRange(10);
        $paginator->setCurrentPageNumber($page);  // from url
        $this->view->paginator = $paginator;      // passed this for generation of pagination
于 2014-01-03T10:02:19.730 回答