Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Created January 2, 2012 10:21
Show Gist options
  • Save Ocramius/1550182 to your computer and use it in GitHub Desktop.
Save Ocramius/1550182 to your computer and use it in GitHub Desktop.
A simple Zend_Paginator that is capable of storing the current page number into a session
<?php
/**
* Description
*
* @author Marco Pivetta <[email protected]>
*/
class SessionAwarePaginator extends Zend_Paginator {
const DEFAULT_SESSION_NS = 'SessionAwarePaginator';
/**
*
* @var Zend_Session_Namespace
*/
protected $_pageNs;
public function __construct($adapter, $ns = self::DEFAULT_SESSION_NS)
{
parent::__construct($adapter);
$this->_pageNs = new Zend_Session_Namespace($ns);
$this->setCurrentPageNumber($this->getCurrentPageNumber());
}
public function setCurrentPageNumber($pageNumber)
{
$this->_pageNs->page = (int) $pageNumber;
parent::setCurrentPageNumber($this->_pageNs->page);
}
public function getCurrentPageNumber() {
$this->_currentPageNumber = (int) $this->_pageNs->page;
return parent::getCurrentPageNumber();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment