Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-27-2008, 06:07 AM
Junior Member
 
Join Date: Mar 2008
Posts: 1
Default Storing a Model in Session/Registry and then accessing

I'm playing around with accessing variables in ZF and was wondering if I am going about this right. Essentially I want to store a Model in session. The model in this case will be the class "Cart".

Bootstrap:
PHP Code:

# cart namespace
$cart = new Zend_Session_Namespace('cart');
if(!isset(
$cart->_data)) $cart->_data = new Cart;

# registry
$registry Zend_Registry::getInstance();
$registry->set('cart'$cart->_data); 
This essentially works pretty well for me, except I find it a bit weird having to create the extra variable "->_data" within the namespace. Normally in PHP I'd just do something like this

PHP Code:

if(!isset($_SESSION['cart'])) $_SESSION['cart'] = new Cart
My main question is whether the extra variable "->_data" is needed. There doesn't seem to be much of a way to just set the namespace 'cart' = new Cart.

Then I access it like this in any of the controllers:

PHP Code:
$cart Zend_Registry::get('cart'); 
Again this is all working ok for me. I'm just a nooob on the ZF so I'm wondering if there is a "Zend" way to do this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:02 AM.