當我處於結果的第一頁時,它可以很好地工作 - 我可以顯示我需要的結果數。 但是當我在另一頁上時,結果的數量不能改變。這是爲什麼?當有一些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))); ?>">
< Nowsze
</a> |
<?php else: ?>
<span class="disabled">< 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 >
</a>
<?php else: ?>
<span class="disabled">Starsze ></span>
<?php endif; ?>
</div>
<?php endif; ?>
我在這種情況下有同樣的問題,我的分頁工作很好,從不同的結果頁面切換到頁面。但我有另一個鏈接在該頁面調用另一個動作,所以它與URL的動作,因此使它worong和通過再次點擊ñ再次他們concccinated ...我dono爲什麼它這樣做 –