Zend_Session学习笔记(源码)
Posted by 机器人 on 29th 十月 2007 in php/javascript
摘自:zendFramework官方参考文档
/** * @author hqlong * @created:2007-10-1 */ public function indexAction(){ require_once 'Zend/Session/Namespace.php'; $defaultNamespace = new Zend_Session_Namespace('Default'); if (isset($defaultNamespace->numberOfPageRequests)) { $defaultNamespace->numberOfPageRequests++; // this will increment for each page load. } else { $defaultNamespace->numberOfPageRequests = 1; // first time } echo "Page requests this session: ", $defaultNamespace->numberOfPageRequests; $authNamespace = new Zend_Session_Namespace('Zend_Auth'); //$authNamespace->lock(); $authNamespace->unlock(); $authNamespace->user = "myusername"; echo $authNamespace->user; //in a web services component $webServiceNamespace = new Zend_Session_Namespace('Some_Web_Service'); $webServiceNamespace->user = "mywebusername"; //防止每个请示有多个实例 // create an instance of a namespace $authSpaceAccessor1 = new Zend_Session_Namespace('Zend_Auth'); // create another instance of the same namespace, but disallow any new instances $authSpaceAccessor2 = new Zend_Session_Namespace('Zend_Auth', true); // making a reference is still possible $authSpaceAccessor3 = $authSpaceAccessor2; $authSpaceAccessor1->foo = 'bar'; if($authSpaceAccessor2->foo=='bar') echo 'ok'; else echo 'not ok'; try { $aNamespaceObject = new Zend_Session_Namespace('Zend_Auth'); } catch (Zend_Session_Exception $e) { echo "Cannot instantiate this namespace since $authSpaceAccessor2 was created\n"; } }
机器人 2007-10-29 于北京