Zend_Session学习笔记(源码)

摘自: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 于北京

此条目发表在 LAMP 分类目录,贴了 , , 标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>