Skip to content

Instantly share code, notes, and snippets.

@dholmes
Created August 22, 2011 19:56
Show Gist options
  • Save dholmes/1163356 to your computer and use it in GitHub Desktop.
Save dholmes/1163356 to your computer and use it in GitHub Desktop.
[ZF] passing options to the pagination control
<?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