[eluser]gypmaster[/eluser]
Hi,
I've got a php5/apache2.0/mysql set up on my local box and I'm trying to follow some code elsewhere but I've got a problem with flashdata. Below is a model designed to update a shopping cart and, two line from the end, set flashdata to say cart has been updated ... I added the echo afterwards just to make sure the code was being executed - it is! ...
Code:
function updateCart($productid, $fullproduct)
{
$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : array(); //pull in existing cart first - copy Session cart to working var $cart!
$totalprice = 0;
if (count($fullproduct))
{
if (isset($cart[$productid])) //check to see if product already exists in cart, if it does, add 1 to count
{
$prevct = $cart[$productid]['count'];
$prevname = $cart[$productid]['name'];
$prevprice = $cart[$productid]['price'];
$cart[$productid] = array(
'name' =>$prevname,
'price' =>$prevprice,
'count' =>$prevct + 1
);
}
else
{
$cart[$productid] = array(
'name' =>$fullproduct['name'],
'price' =>$fullproduct['price'],
'count' =>1
);
}
// Loop through cart adding up total Cost
foreach ($cart as $id =>$product)
{
$totalprice += $product['price'] * $product['count'];
}
$_SESSION['totalprice'] = $totalprice;
$_SESSION['cart'] = $cart; //Set Session cart to the working var $cart
$this->session->set_flashdata('conf_msg', "We've added this product to your cart.");
echo "inside flash: ". $this->session->flashdata('conf_msg');
}
}
Here's the relevant part of the controller:
Code:
function cart($productid=0)
{
if ($productid > 0)
{
$fullproduct = $this->MProducts->getProduct($productid);
$this->MOrders->updateCart($productid,$fullproduct);
redirect('welcome/product/'.$productid, 'refresh');
}
Here's the relevant part of the view:
Code:
if ($this->session->flashdata('conf_msg'))
{
echo "<div class='message'>message";
echo $this->session->flashdata('conf_msg');
echo "</div >";
}
Anyone know what I'm doing wrong?
Cheers.