Re: Appending data in Session
Thanks. Amit's solution was what I was looking for. I do realize that by separating product id into different fields might be beneficial, but appending data into the same array looks more appealing to me. Anyway, this actually pretty easy to tackle, I just never thought of it like this. Heh. Thanks alot for your help. Appreciate it. On May 22, 2008, at 9:39 PM, fr3nch13 wrote: > > forgot, this also eliminates the need to check to see if it's there > first. > > On May 22, 10:38 am, fr3nch13 <[EMAIL PROTECTED]> wrote: >> to add onto b logics, you can use the id as the key in an associative >> array as the sessions use the period as it's delim: >> >> writing: >> >> $this->Session->write('product.'.$id, $name); >> >> reading >> >> $products = $this->Session->read('product); >> >> On May 22, 10:26 am, "b logica" <[EMAIL PROTECTED]> wrote: >> >>> Additionally, if it were my app, I'd save the product name also so >>> that a list for the current cart can be easily displayed at any >>> time. >>> So, instead of pushing an ID onto the array I'd first grab all of >>> the >>> products from session, add a new array with both ID & name of latest >>> product, then both save the products array back to the session as >>> well >>> as make it available to the view with set(). >> >>> Just my $0.02 >> >>> On Thu, May 22, 2008 at 6:46 AM, Amit Badkas <[EMAIL PROTECTED]> >>> wrote: 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 -~--~~~~--~~--~--~---
Re: Appending data in Session
forgot, this also eliminates the need to check to see if it's there first. On May 22, 10:38 am, fr3nch13 <[EMAIL PROTECTED]> wrote: > to add onto b logics, you can use the id as the key in an associative > array as the sessions use the period as it's delim: > > writing: > > $this->Session->write('product.'.$id, $name); > > reading > > $products = $this->Session->read('product); > > On May 22, 10:26 am, "b logica" <[EMAIL PROTECTED]> wrote: > > > Additionally, if it were my app, I'd save the product name also so > > that a list for the current cart can be easily displayed at any time. > > So, instead of pushing an ID onto the array I'd first grab all of the > > products from session, add a new array with both ID & name of latest > > product, then both save the products array back to the session as well > > as make it available to the view with set(). > > > Just my $0.02 > > > On Thu, May 22, 2008 at 6:46 AM, Amit Badkas <[EMAIL PROTECTED]> wrote: > > > 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 -~--~~~~--~~--~--~---
Re: Appending data in Session
to add onto b logics, you can use the id as the key in an associative array as the sessions use the period as it's delim: writing: $this->Session->write('product.'.$id, $name); reading $products = $this->Session->read('product); On May 22, 10:26 am, "b logica" <[EMAIL PROTECTED]> wrote: > Additionally, if it were my app, I'd save the product name also so > that a list for the current cart can be easily displayed at any time. > So, instead of pushing an ID onto the array I'd first grab all of the > products from session, add a new array with both ID & name of latest > product, then both save the products array back to the session as well > as make it available to the view with set(). > > Just my $0.02 > > On Thu, May 22, 2008 at 6:46 AM, Amit Badkas <[EMAIL PROTECTED]> wrote: > > 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 -~--~~~~--~~--~--~---
Re: Appending data in Session
Additionally, if it were my app, I'd save the product name also so that a list for the current cart can be easily displayed at any time. So, instead of pushing an ID onto the array I'd first grab all of the products from session, add a new array with both ID & name of latest product, then both save the products array back to the session as well as make it available to the view with set(). Just my $0.02 On Thu, May 22, 2008 at 6:46 AM, Amit Badkas <[EMAIL PROTECTED]> wrote: > 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 -~--~~~~--~~--~--~---
Re: Appending data in Session
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 -~--~~~~--~~--~--~---