繁体   English   中英

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

[英]Zend Paginator: Show pagination links without loading(NON-DB) data

我正在使用一项服务,一次可以获取过滤器的结果和结果总数。 详细说明,假设总共有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]等,因为我知道数据总数。

我为此进行了很长时间的研究,但是在解决数据库查询的所有地方,我都没有从数据库中获得此​​结果,它来自将XML格式转换为数组的服务。

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

我如何发送总计数,以使其在不加载所有数据的情况下创建其他分页链接,因为我由于加载100,000条记录而收到了Memory Exhaust致命错误,而且每次获取所有记录时都出现了未优化的方式,当我有25条记录时,它只显示25条记录每个服务请求中的TOTAL COUNT个。

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

las,得到了有效的解决方案: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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM