2011-10-06 43 views
0

當我處於結果的第一頁時,它可以很好地工作 - 我可以顯示我需要的結果數。 但是當我在另一頁上時,結果的數量不能改變。這是爲什麼?當有一些GET參數時,Zend_paginator不會更改perPage值

當我如第3頁,而且我顯示12每頁和我嘗試將其更改爲60,在鏈路的末端,我有:

perPage/12/submitPagin/Zastosuj/page/3?perPage=60&submitPagin=Zastosuj 

任何想法,任何人? :)

public listAction(){   
(...) 
    $params = $this->_parseSearchParams($this->getRequest()->getParams()); 
    $searchForm = new ListIndexForm(); 
    $searchForm->setAction(''); 
    $searchForm->setDefaults($params); 

    $this->view->searchForm = $searchForm; 
    $this->view->params = $params; 

    $auth = Zend_Auth::getInstance(); 

    $sql = 'SELECT * FROM Images order by created desc LIMIT 500'; 
    $result = $db->fetchAll($sql); 
    $this->view->images = $result; 

    $page=$this->_getParam('page',1); 
    $paginator = Zend_Paginator::factory($result); 

    $paginator->setCurrentPageNumber($this->getRequest()->getParam('page', 1)); 

    $paginator->setItemCountPerPage($params[ 'perPage' ]); 

    $this->view->paginator = $paginator; 
} 

我的函數來分析PARAMS:

private function _parseSearchParams ($params) 
{ 
    if (! isset($params[ 'perPage' ])) { 
     $params[ 'perPage' ] = 24; 
    } 

    foreach ($params as $key => $value) { 
     if (is_null($value) or $value == '') { 
      unset($params[ $key ]); 
      continue; 
     } 


     switch ($key) { 
      case 'tags': 
      case 'im': 
      case 'module': 
      case 'submitupdate': 
      case 'controller': 
      case 'action': 
      case 'submit': 
       unset($params[ $key ]); 
       continue; 
      break; 

     } 
    } 

    return $params; 
} 

我的形式來改變每頁的結果數:

class ListIndexForm extends Zend_Form { 
public function __construct($options = null) { 
    parent::__construct ($options); 
    $this->setMethod ('GET'); 


    $perPageValues = array(
     6 => 6, 
     12 => 12, 
     18 => 18, 
     24 => 24, 
     30 => 30, 
     60 => 60, 
     900 => 90, 
     150 => 150, 
     300 => 300, 
     600 => 600, 
    ); 
    $this->addElement ('Select', 'perPage', 
     array (
      'filters'   => array(
      'Digits' 
     ),   
      'label'    => 'Obrazków na stronę', 
      'MultiOptions'  => $perPageValues, 
      'value'    => 24, 
     ) 
    ); 

    $this->addElement ('Submit', 'submitPagin', 
    array (
      'label' => 'Zastosuj', 
    ) 
    ); 

} 

}

視圖list.phtml :

(...) 
<?=$this->searchForm;?> 
<?foreach ($this->paginator as $row):?> 
<?=$row['id']?> 
<?enforeach;?> 
<?= $this->paginationControl($this->paginator, 'Sliding', '../helpers/searchpagination.phtml', array('urlParams' => $this->params)); ?> 

searchpagination.phtml幫手:

<?php 
    $urlParams = isset($this->urlParams) ? $this->urlParams : array(); 
?> 

<?php if ($this->pageCount): ?> 
<div class="paginationControl"> 
<!-- Previous page link --> 
<?php if (isset($this->previous)): ?> 
<a href="<?= $this->url(array_merge($urlParams, array('page' => $this->previous))); ?>"> 
&lt; Nowsze 
</a> | 
<?php else: ?> 
<span class="disabled">&lt; Nowsze </span> | 
<?php endif; ?> 

<!-- Numbered page links --> 
<?php foreach ($this->pagesInRange as $page): ?> 
<?php if ($page != $this->current): ?> 
<a href="<?= $this->url(array_merge($urlParams, array('page' => $page))); ?>"> 
    <?= $page; ?> 
</a> | 
<?php else: ?> 
<?= $page; ?> | 
<?php endif; ?> 
<?php endforeach; ?> 

<!-- Next page link --> 
<?php if (isset($this->next)): ?> 
<a href="<?= $this->url(array_merge($urlParams, array('page' => $this->next))); ?>"> 
Starsze &gt; 
</a> 
<?php else: ?> 
<span class="disabled">Starsze &gt;</span> 
<?php endif; ?> 
</div> 
<?php endif; ?> 
+0

我在這種情況下有同樣的問題,我的分頁工作很好,從不同的結果頁面切換到頁面。但我有另一個鏈接在該頁面調用另一個動作,所以它與URL的動作,因此使它worong和通過再次點擊ñ再次他們concccinated ...我dono爲什麼它這樣做 –

回答

0

你似乎是指定兩次perPage參數。 (Zend Framework將兩者都視爲GET參數)

perPage/12/submitPagin/Zastosuj/page/3? perPage = 60 & submitPagin = Zastosuj

如果將第一個更改爲60,會發生什麼情況?我意識到這可能會導致您的網址結構出現問題。

+0

我想通了,但我還沒有任何想法,如何做到這一點。 – rukya

相關問題