[eluser]bang_dayat[/eluser]
I learn about Thomas myer book,..it pass both of PHP Session and CI Session to develop Shopping cart application,..I create the Model like this:
Quote:<?php
class MOrders extends model{
function MOrders(){
parent::model();
}
function updateCart($productid,$fullproduct){
$cart = $_SESSION['cart'];
$totalprice=0;
if(count($fullproduct)){
if(isset($cart[$productid])){
$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
);
}
foreach($cart as $id => $product){
$totalprice += $product['price']*$product['count'];
}
$_SESSION['totalprice']=$totalprice;
$_SESSION['cart']=$cart;
$this->session->set_flashdata('conf msg',"anda telah menambah produk ini ke keranjang belanja");
}
}
}
?>
then in the cart controller like this:
Quote:function cart($productid=0){
//gunakan sebagai keranjang belanja
if($productid > 0){
$fullproduct = $this->MProducts->getProduct($productid);
$this->MOrders->updateCart($productid,$fullproduct);
redirect('welcome/product/'.$productid,'refresh');
}
else{
$data['title']="toko online | keranjang belanja";
if (count($_SESSION['cart']) == true){
$data['main'] = '';
$data['navlist'] = $this->MCats->getCategoriesNav();
$this->load->vars($data);
$this->load->view('template');
}
else{
redirect('welcome/index','refresh');
}
}
}
but in the first time I run that application,,I found the error message like this:
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined index: cart
Filename: models/morders.php
Line Number: 7
Quote:A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\CI_system\libraries\Exceptions.php:166)
Filename: libraries/Session.php
Line Number: 662
Quote:A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\CI_system\libraries\Exceptions.php:166)
Filename: helpers/url_helper.php
Line Number: 539
Please Someone Help Me to find the Problem,,..Thanx A LOT