Zend Framework Session: Locking and Unlocking Namespace


Zend Framework Session Step By Step Tutorial - Part 5: Session namespaces can be locked. What's that mean? When a namespace session is locked, we can not update or delete value of session. it will be read-only.

We can use lock() to lock namespace. Then, if want to check whether locked or not, use isLocked(). Look this sample:

  public function loginFormAction()
  {
	
    $ns = new Zend_Session_Namespace('HelloWorld');
	$ns->lock();

    if (!$ns->isLocked()) {
	  if(!isset($ns->yourLoginRequest)){
	    $ns->yourLoginRequest = 1;
	  }else{
	    $ns->yourLoginRequest++;
	  }
    }
	 
    $request = $this->getRequest();      
	$this->view->assign('request', $ns->yourLoginRequest);
	$this->view->assign('action', $request->getBaseURL()."/user/auth");  
    $this->view->assign('title', 'Login Form');
    $this->view->assign('username', 'User Name');	
    $this->view->assign('password', 'Password');	
	
  }

To unlock, you can use unLock() method.

$ns= new Zend_Session_Namespace('HelloWorld');

// marking session as read only locked
$ns->lock();

// unlocking read-only lock
if ($ns->isLocked()) {
    $ns->unLock();
}



Series this article:
Zend Framework Session: Introduction
Zend Framework Session: Using Namespace
Zend Framework Session: Accessing Session Data
Zend Framework Session: Seing All Values at Namespace
Zend Framework Session: Locking and Unlocking Namespace
Zend Framework Session: Automatic Expiration

Bookmark and Share Tag: framework, zend, zend framework, session, namespace Category: PHP Framework Post : April 23rd 2008 Read: 32,512

advertisements


blog comments powered by Disqus