日期:2014-05-16 浏览次数:20519 次
class CartTool
{
private static $ins;
private $good = array();
final private function __construct()
{
}
final private function __clone()
{
}
// 获取实例
protected static function getIns()
{
if(!(self::$ins instanceof self))
{
self::$ins = new self();
}
return self::$ins;
}
/**
* 函数作用:把购物车的单例对象放到session里
*
*
* @return instance 购物车的单例对象
* */
public static function getCart()
{
if(!isset($_SESSION['cart']) || !($_SESSION['cart'] instanceof self))
{
echo '1';
$_SESSION['cart'] = self::getIns();
}
return $_SESSION['cart'];
}