On Thu, May 22, 2008 at 3:16 PM, Reza Muhammad <[EMAIL PROTECTED]> wrote:
> > Hello, > > I'm trying to save multiple data in a session (kind of like a shopping > cart). The process is a user select an item using a checkbox, and > then he/she submits the form. > > The function will write a session (called product_id). However, if I > try to search for another item, and then I submit the form again, the > session only holds the newest data. > > Can't I just do this with $this->Session->write('products', $this- > >data['Products']['id']); ? - You need to do session read and array merge for this, like $this->Session->write('products', am($this->Session->read('products'), array($this->data['Products']['id']))); Also check if products are in session before doing array merge, like if ($this->Session->check('products')) { $this->Session->write('products', am($this->Session->read('products'), array($this->data['Products']['id']))); } else { $this->Session->write('products', array($this->data['Products']['id'])); } -- Amit http://amitrb.wordpress.com/ http://coppermine-gallery.net/ http://cheesecake-photoblog.org/ http://www.sanisoft.com/blog/author/amitbadkas --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---