Created
January 2, 2012 10:21
-
-
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
This file contains hidden or 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 | |
/** | |
* 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