Hi Folks,

This is a complete noob question, so please bear with me. I'm learning
OOP/MVC & ZF, so it's a bit of an uphill struggle at times!

I am trying to implement a basic shopping cart style system, using
Zend_Session to remember what the user has placed into the basket.  My
problem is that I cannot seem to store & retrieve more than one array
into the session namespace object.

In my Controller I start with

  $basketSessionNamespace = new Zend_Session_Namespace('basket');

Once I have obtained the product info from the Model, I put it into the
basket like this:

  $basketSessionNamespace->array[$orderedProduct] = $productInfo;

In the last line, $orderedProduct is the name of the product (e.g.
'tomatoes').  I am therefore trying to create an associative array in
$basketSessionNamespace.  Within this associative array, $productInfo
(another array) contains all the data of the selected product that I
want to send to the View.

In the View I have tried to grab the basketSessionNamespace data by
calling it again:

  $basketSessionNamespace = new Zend_Session_Namespace('basket');

I have also sent the data from the Controller to the View by calling it
such:

   $this->view->basket = $basketSessionNamespace;

In either case, the only data to be available in the View is the last
array I created.  E.g.

  $basketSessionNamespace->array['tomatoes'] = $productInfo;

If my Controller was previously called with the action to add something
to the basketSessionNamespace, e.g.
$basketSessionNamespace->array['cucumber'] ...

...then this previous product doesn't seem to be available.  I am
testing this in the view by doing a foreach($basketSessionNamespace as
$product) { ... }

I am finding it hard to investigate because the session object is
protected and cannot be exposed using var_dump or print_r.

My target environment is RHEL 5 (so PHP 5.1.6) so I'm using ZF 1.6.2
(old, I know, but cannot change this).  One final note - my bootstrap
has Zend_Session::start();

I have followed the docs as far as possible but seem to be stuck on this
aspect of implementation.

If anyone can advise, I'd really appreciate it.  Sorry for the long email!

Many thanks,
-- 
Steve

HP Compaq 6715b | fedora 13 | AMD Turion TL-60 | 4GB | Momentus 5400.3

Reply via email to