結果の最初のページにいるときは、完全に機能します。必要な結果の数を表示できます。しかし、私が別のページにいるときは、結果の数を変更することはできません。何故ですか?
たとえば、3ページで、1ページあたり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;
}
パラメータを解析する私の関数:
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;
}
1ページあたりの結果数を変更するための私のフォーム:
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; ?>