Sessions and Classes
| From: | PHP-List | Date: | Wed, 06 Feb 2002 07:18:28 +0000 |
| Subject: | Sessions and Classes | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-83681@lists.php.net to get a copy of this message | ||
What is the proper way to transfer class properties through-out my pages...
let's say i have a ShoppingCart Class and i have methods like
addToCart(id, qty) and deleteFromCart(id)
also i have properties like CartItems("id" => array(), "qty"=> array())
this is what i do...
//when the user enters my site, i do some...
-------------
if (!session_is_registered("myCart")){
$myCart = new ShoppingCart();
.... (some other stuffs...)
session_register("myCart");
}
else {
$myCart = new ShoppingCart();
}
--------------
if the object in the session is not present
i would create an instance and then register
it to the session.
else if it is present, i would just reconstruct it...
because if i don't, even though it is in the
sessions, the properties and methods are
not constructed (no handler, i don't know how
to call it).
my code works, but is there any other way
to do this, because i think it's kinda slow....
another question, is it ok to have a database-driven
shopping cart? i make use of the database to as the
actual cart holder?
i need your opinions on these....
thanks!
Brian Feliciano
-------
i lost my connection to the list for a while, so
i have never heard your answers, please post it again or
email it to me directly..
thanks...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php