[eluser]johanriyan[/eluser]
Hello guys,
please help me,
when i am submit buy, my cart not work,
here my Controller :
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cart extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('m_admin');
}
public function index(){
$data['title']="Cart";
$this->load->view('include/header',$data);
$this->load->view('include/menu');
$data['produk']=$this->m_admin->getProduk();
$this->load->view('v_cart',$data);
$this->load->view('include/footer');
}
public function add()
{
$product = $this->m_admin->get($this->input->post('id'));
$data = array(
'id' => $this->input->post('id'),
'qty' => 1,
'price' => $product->price,
'name' => $product->name
);
$this->cart->insert($data);
redirect('cart');
}
}
and this is my view :
Code:
<ul class="thumbnails">
<?php foreach($produk as $item){?>
<?php echo form_open('cart/add'); ?>
<li class="span4">
<div class="thumbnail">
<img src="http://placehold.it/320x200" alt="ALT NAME">
<div class="caption">
<h3><?php echo $item->name;?></h3>
<p>Rp. <?php echo number_format($item->price,2,',','.');?></p>
<input type="hidden" name="id" value="<?php echo $item->id ?>">
<input type="submit" class="btn btn-primary btn-block" value="Buy">
</div>
</div>
</li>
<?php }?>
</ul>
<table class="table">
<tbody>
<?php foreach($this->cart->contents() as $result): ?>
<tr>
<td><?php echo $result['name'] ?></td>
<td>Small</td>
<td>
<input type="number" 45px; padding: 1px" value="0">
</td>
<td><?php echo $this->cart->total(); ?></td>
<td>
<input type="number" 45px; padding: 1px" value="0">
</td>
<td>Large</td>
<td>
<input type="number" 45px; padding: 1px" value="0">
</td>
<td>Ultra</td>
<td>
<input type="number" 45px; padding: 1px" value="0">
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
This is my config :
Code:
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
and autoload :
Code:
$autoload['libraries'] = array('database','pagination','session','form_validation','cart');
/*
| -------------------------------------------------------------------
| Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['helper'] = array('url', 'file');
*/
$autoload['helper'] = array('url','form');
how to fix it.
i am using codeigniter version 2.1.3.