2011-10-06 6 views
0

결과의 첫 페이지에있을 때 완벽하게 작동합니다. 필요한 결과 수를 표시 할 수 있습니다. 그러나 다른 페이지에있을 때 결과의 수를 변경할 수 없습니다. 왜 그런가요?Zend_paginator는 일부 GET 매개 변수가있을 때 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

이 시나리오에서 동일한 문제가 있습니다. 내 페이지 매김이 페이지마다 다른 result.but 페이지로 전환하는 것이 효과적입니다. 다른 작업을 호출하는 페이지에 다른 링크가 있으므로 URL에 해당 동작이 병행 될 수 있습니다. 그것을 다시 클릭하면 다시 concatenated됩니다 ... 나는 왜 그렇게하는 것입니까 –

답변

0

당신은 두 번 perPage 매개 변수를 지정 것으로 나타났습니다. (Zend Framework는 GET 매개 변수로 두 가지를 볼 수 있습니다.)

perPage/12/submitPagin/Zastosuj/page/3? perPage = 60 & submitPagin = 자 스토 수

첫 번째 값을 60으로 변경하면 어떻게됩니까? URL 구조에 문제가 발생할 수 있음을 알고 있습니다.

+0

나는 이것을 알아 냈습니다. 그러나 여전히 나는 그것을 할 수있는 아이디어가 없습니다. – rukya