Witam,
szukam informacji na temat używania seji w Zend Framework, może ktoś gdzieś widział coś na ten temat, albo wie coś o tym więcej? Może jakiś tutorial z np. systemem logowania?
Z góry wielkie dzięki
Pozdrawiam
<?php Rapide::loadInterface('Rapide_Session_Interface'); Rapide::loadClass('Rapide_Session_Exception'); Rapide::loadInterface('Rapide_Session_Handler_Interface'); class Rapide_Session { private $_bSessionStarted = false, $_sNameSpace; public function __construct($sNameSpace = null) { { $this->_sNameSpace = $sNameSpace; } } public function getNameSpaceName() { return $this->_sNameSpace; } public function setHandler(Rapide_Session_Handler_Interface $oHandler) { if($this->started()) { $sError = 'Session has already started'; throw new Rapide_Session_Exception($sError); } ( ); } public function started() { } public function start() { if(!$this->started()) { { $sError = 'Headers has already sent'; throw new Rapide_Session_Exception($sError); } } } public function close() { if(!$this->started()) { $sError = 'Session has not started yet'; throw new Rapide_Session_Exception($sError); } else $this->destroy(); } public function destroy() { if(!$this->started()) { $sError = 'Session has not started yet'; throw new Rapide_Session_Exception($sError); } } public function __get($sParameters) { if(!$this->started()) { $sError = 'Session has not started yet'; throw new Rapide_Session_Exception($sError); } { $_SESSION[$this->_sNameSpace][$sParameters] : null; } else { $_SESSION[$sParameters] : null; } } public function __set($sParameters, $mValue) { if(!$this->started()) { $sError = 'Session has not started yet'; throw new Rapide_Session_Exception($sError); } $_SESSION[$this->_sNameSpace][$sParameters] = $mValue; else $_SESSION[$sParameters] = $mValue; } public function __isset($sParameters) { if(!$this->started()) { $sError = 'Session has not started yet'; throw new Rapide_Session_Exception($sError); } else } public function getNameSpace() { if(!$this->started()) { $sError = 'Session has not started yet'; throw new Rapide_Session_Exception($sError); } return $_SESSION[$this->_sNameSpace]; else return $_SESSION; } } ?>
<?php Rapide::loadInterface('Rapide_User_Interface'); Rapide::loadClass('Rapide_User_Exception'); Rapide::loadClass('Rapide_Session'); class Rapide_User implements Rapide_User_Interface { private $_oSession, $_oDataSession; public function __construct() { $this->_oSession = new Rapide_Session('Rapide_User'); $this->_oDataSession = new Rapide_Session('Rapide_User_Data'); $this->_oSession->start(); $this->_oDataSession->start(); $this->_oSession->authenticated = false; } public function getGroups() { return $this->_oSession->groups; } { { $sError = 'Argument 1 for Rapide_User::setGroups() must be an array'; throw new Rapide_User_Exception($sError); } $this->_oSession->groups = $aGroups; } public function hasGroup($sGroup) { foreach($this->getGroups() as $iKey => $sUserGroup) { if($sUserGroup == $sGroup) return true; } return false; } public function isAuthenticated() { return $this->_oSession->authenticated; } public function setAuthenticated($bAuthenticated = true) { $this->_oSession->authenticated = (bool)$bAuthenticated; } public function __get($sParameter) { return $this->_oDataSession->$sParameter; } public function __set($sParameters, $mValue) { $this->_oDataSession->$sParameter; } public function __isset($sParameter) { } public function destroy() { $this->setAuthenticated(false); $this->_oSession->close(); $this->_oDataSession->close(); } } ?>
<?php $oUser = new Rapide_User; $oUser->zmienna = 'wartosc'; ?>
<?php $oUser->setAuthenticated(); ?>
<?php if($oUser->isAuthenticated()) { //cos } ?>
<?php abstract class Rapide_Plugin implements Rapide_Plugin_Interface { // metoda wywolana przed rozpoczeciem dispatchingu public function preDispatchLoop(Rapide_Dispatcher_Token_Interface $oToken) { return $oToken; } // wywolywana po zakonczeniu dispatchingu public function postDispatchLoop(Rapide_Dispatcher_Token_Interface $oToken) { return $oToken; } // wywolana przed uruchomieniem akcji public function preExecution(Rapide_Dispatcher_Token_Interface $oToken) { return $oToken; } // po zakonczeniu akcji public function postExecution(Rapide_Dispatcher_Token_Interface $oToken) { return $oToken; } } ?>
<?php Rapide_Plugin_Security implements Rapide_Plugin_Interface { public function preExecution(Rapide_Dispatcher_Token_Interface $oToken) { { $oToken = new Rapide_Dispatcher_Token('Error', 'Error403'); } return $oToken; } } ?>
<?php class LoginControl implements Zend_Controller_Plugin_Interface { public function preDispatch (Zend_Controller_Dispatcher_Token $action) { return $action; } } ?>