Re: Re: Creating an OO Shopping Cart

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You don't need the unserialize(), it's done internally by the
session_start().
All the things you put inside $_SESSION, except for resources, will be
rebuilt when the session is regenerated. This way you don't need to worry
about serializing.
Read the manual section about sessions.

2006/4/21, Steve <email.weblists@xxxxxxxxx>:
>
> Hi
>
> Thanks for all your help so far.
>
> I've combined all your thoughts, and from what I understand, for every
> page I have that interacts with the cart, I need to have something like
> the following code.
>
> So basically, on every page, be it a page that displays the contents of
> the cart, the checkout, or catalog pages, at the top of the code I
> always need to check if files are being added, deleted or changed qty.
> Is this correct?
>
> This is my biggest concern. What's the best way to interact with the
> Cart class when adding/removing items?
>
> Thanks
> Steve
>
>
> <?php
>
> // This File: catalog.php
> require_once 'Cart.php';
> session_start();
>
> /* Establish connection to the cart
> ************************************ */
> if ( isset($_SESSION["cart"] )
>     $cart = unserialize($_SESSION["cart"]);
> else
>     $cart = new Cart();
>
> /* Modify the cart for this user
> ************************************ */
> if ( isset($_GET['add']) )
>     $cart->addItem($_GET['add']);
> if ( isset($_GET['remove']) )
>     $cart->removeItem($_GET['remove']);
>
> /* Save the cart's state
> ************************************ */
> $_SESSION['cart'] = $cart;
>
> /* Display the catalog
> ************************************ */
> echo <<<HEREDOCS
> blah blah
> HEREDOCS;
>
> ?>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux