簡體   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