yamcsha

Zend Session example

Sep 11th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.72 KB | None | 0 0
  1. <?php
  2.  
  3. /*in the Bootstrap.php file in application/ folder put this code to initiate the session:*/
  4.  
  5. protected function _initSession()
  6. {
  7.     $session = new Zend_Session_Namespace('your-project-name-here', true);
  8.     $session->setExpirationSeconds(7*86400); // expire in 7 days
  9.     Zend_Registry::set('session', $session);
  10. }
  11.  
  12. /* to use it to store data between requests: */
  13. public function exampleFirstAction() {
  14.     $session = Zend_Registry::get('session');
  15.  
  16.     // set data in session
  17.     $session->foo = 'bar';
  18. }
  19.  
  20. public function exampleSecondAction() {
  21.     $session = Zend_Registry::get('session');
  22.  
  23.     // get data from session in other place
  24.     if (isset($session->foo)) {
  25.         echo $session->foo;
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment