Zend_paginator doesn't change perPage value, when there're some GET parameters
It works perfectly, when I am on first page of the results - I can display the number of results I need. But when I'm on another page, the number of results cannot be changed. Why is that?
And when I'm for example on 3 page, and I'm displaying 12 per page and I try to change it to 60, on the end of link I have:
perPage/12/submitPagin/Zastosuj/page/3?perPage=60&submitPagin=Zastosuj
Any ideas, anyone? :)
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;
}
my function to parse 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;
}
My form to change the number of the results per page:
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->addElemen开发者_开发百科t ( 'Submit', 'submitPagin',
array (
'label' => 'Zastosuj',
)
);
}
}
view 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 helper:
<?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; ?>
You appear to be specifying the perPage parameter twice. (Zend Framework sees both as GET parameters)
perPage/12/submitPagin/Zastosuj/page/3?perPage=60&submitPagin=Zastosuj
What happens if you change the first one to 60? I realise this may cause problems for your URL structure.
精彩评论