My apollogies.
The top problem seems to be working now so presume there was a syntax error somewhere, and I'm using php5.
The second problem occures when I do this more than once:
(It was doing it every time until I added __autoload() )
I call addToCartAction.php
It creates a ShoppingCartDelegate and sends an OrderVO off to it
It then calls shoppingCartDelegate->addToCart()
But when ShoppingCartDelegate's addToCart() invokes $this->cart->getOrderLines()
I get:
The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "OrderVO" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition
addToCartAction.php
<?php
include_once('../myphp/ShoppingCartDelegate.inc');
include_once('../myphp/OrderVO.inc');
$shoppingCart = new ShoppingCartDelegate();
if(!$SESSION['cart'])$SESSION['cart']= new OrderVO();
// set cart up in delegate
$shoppingCart->setCart($_SESSION['cart']);
// effect cart
$shoppingCart->addToCart($itemToAdd,$quantity);
// set back in session
$_SESSION['cart']= $shoppingCart->getCart();
?>
ShoppingCartDelegate.inc
<?php
include_once('User.inc');
include_once('UserVO.inc');
require_once('OrderVO.inc');
require_once('OrderLineVO.inc');
include_once('ProductVO.inc');
class ShoppingCartDelegate
{
private $cart;
function construct(){$this->cart = new OrderVO();}
function autoload($class_name) { require_once $class_name.'.inc';}
// takes an OrderVO
public function setCart($cart)
{
$this->cart = $cart;
}
// returns an OrderVO
public function getCart()
{
return $this->cart;
}
// takes String productId, int quantity
public function addToCart($productID, $quantity)
{
$item = new ProductVO();
$item->setProductCode($productID);
$item->setDescription($productID);
$item->setPrice(10);
// cart is an OrderVO and getOrderLines is an array
$orderLines = $this->cart->getOrderLines(); // This is where it errors
}
?>
OrderVO.inc (Is just a simple Value Object)
<?php
class OrderVO
{
private $orderLines= array();
function construct(){$this->orderLines=array();}
function autoload($class_name) { require_once $class_name.'.inc';}
public function getOrderLines(){ return $this->orderLines; }
public function setOrderLines($orderLines){ $this->orderLines=$orderLines; }
}
?>