Zend Framework Session: Seing All Values at Namespace


Zend Framework Session Step By Step Tutorial - Part 4: This is a little tips to show all value at a namespace. As we know, session can have behavior like array. So, we can show values like array. Look this sample:
$ns = new Zend_Session_Namespace('HelloWorld');
foreach ($ns as $index => $value) {
  echo "ns->$index = '$value';";
}

Ok, try to test it. We have put session at loginform and userpage page. Now, we want to show request statistic for that page. Open your "UserController.php" within application/controllers. Add following method:

  public function statsAction()
  {
    $ns = new Zend_Session_Namespace('HelloWorld');
    foreach ($ns as $index => $value) {
      echo "ns->$index = '$value';";
	  echo "<br />";
    }

  }

Then, create a view for this action controller. Create a file named "stats.phtml" within application/views/scripts/user. Leave blank.

Ok, try to point your browser to http://localhost/test/zend/helloworld/web_root/user/stats. You may get such as:

ns->yourLoginRequest = '2';
ns->yourUserPageRequest = '7';

Values depend on number of visiting.



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: Category: PHP Framework Post : April 23rd 2008 Read: 33,307

advertisements


blog comments powered by Disqus