Zend_Session 和Zend_Session_ 实例:(简单的用户登录和退出)
render("index"); } public function loginAction(){ $username = $this->getRequest()->getParam('username'); $password = MD5($this->getRequest()->getParam('password')); if($username != '' && $password != ''){ $table = new Admin(); $db = $table->getAdapter(); $where = $db->quoteInto('username = ?', $username) . $db->quoteInto('AND password = ?', $password); $users = $table->fetchAll($where)->toArray(); if(count($users)>0){ $session = new Zend_Session_Namespace('admin'); //$session->uid = $users[0]['uid']; $session->username = $users[0]['username']; $this->view->username = $session->username; $this->_forward('index','index'); }else{ $this->view->mes = "用户名或密码错误"; $this->_forward('err','global'); } }else{ $this->_forward('err','global'); } } public function loginoutAction(){ $session = new Zend_Session_Namespace('admin'); $session->__unset("admin"); $this->_forward('index','index'); } }?>
如果想移出该session中所有变量可用 $session->unsetAll();