Created
August 22, 2011 19:56
-
-
Save dholmes/1163356 to your computer and use it in GitHub Desktop.
[ZF] passing options to the pagination control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* In your controller action */ | |
class search extends Zend_Controller{ | |
public function searchResultsAction() | |
{ | |
$request = $this->getRequest(); | |
$sort = $request->getParam('sort','date'); | |
$this->view->sort = $sort; | |
$pageSize = (int) $request->getParam('pagesize',10); | |
if( $pageSize <= 0 or $pageSize > 250){ | |
$pageSize = 10; | |
} | |
$this->view->pagesize = $pageSize; | |
Zend_Paginator::setDefaultItemCountPerPage($pageSize); | |
/** Load the results into $results somehow **/ | |
$paginator = Zend_Paginator::factory($results); | |
$paginator->setCurrentPageNumber($request->getParam('page')); | |
$this->view->paginator = $paginator; | |
} | |
} | |
/* Now, in your search-results.phtml view */ | |
/* Somewhere you have this to show the control */ | |
<?php | |
$pageUrlOptions = array( | |
'page'=>$this->page, | |
'size'=>$this->size, | |
'sort'=>$this->sort | |
); | |
if($this->paginator) { | |
echo $this->paginationControl( | |
$this->paginator, | |
'sliding', | |
'_partials/paging-controls.phtml', | |
$pageUrlOptions); | |
} | |
?> | |
/* | |
Finally, in your _partials/paging-controls.phtml you can just access the options as $this->sort or $this->size, etc | |
pass them to $this->url , escape a query string, etc | |
More info on the pagination template may be found here: http://framework.zend.com/manual/en/zend.paginator.usage.html#zend.paginator.usage.rendering.example-controls | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment