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?