Zend Paginator:显示分页链接而不加载(NON-DB)数据

时间:2013-12-30 06:59:30

标签: php zend-framework pagination zend-paginator

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

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

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

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

我研究了很长时间,但是每个解决方案都用于数据库查询,而且我没有从DB获得这个结果,它来自导致XML格式的服务,该格式被转换为数组。

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

我如何发送总计数,以便在没有加载所有数据的情况下创建其他分页链接,因为我收到了10万条记录,因为我收到了内存排放致命错误。当我在每个服务请求中都有TOTAL COUNT时,它也看起来没有优化的方式每次获取所有记录只显示25条记录。

pagination.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; ?>

1 个答案:

答案 0 :(得分: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