我有一個問題,當我嘗試將購物車添加到購物車。購物車無法進入購物車。Codeigniter - 爲什麼加入購物車不起作用?
這是我的控制器:
public function buy($product_id)
{
$product = $this->m_produk->find($product_id);
$data = array(
'id' => $product->id,
'qty' => 1,
'nama' => $product->nama,
'harga' => $product->harga
);
$this->cart->insert($data);
redirect('produk/index');
}
這是我的模型加入購物車:
public function find($id){
$hasil = $this->db->where('id',$id)
->limit(1)
->get('produk');
if ($hasil->num_rows() > 0) {
return $hasil->row();
}else {
return array();
}
}
這是我的看法:
<?php
foreach ($produk as $product) {
?>
<div class="thumbnail">
<img src="<?php echo base_url(''.$product->gambar);?>" width="200" height="200" class="img-rounded center-block" alt=""/>
<div class="caption">
<h4 class="text-center"><?php echo $product->nama?></h4>
<h4 class="text-center">RP.<?php echo $product->harga?>,00</h4>
<!-- <a href="#" class="link-class btn btn-primary center-block" role="button">add to cart</a> -->
<?=anchor('produk/buy/'.$product->id,'add to cart' , [
'class' => 'btn btn-primary' , 'role' => 'button'
]) ?>
</div>
</div>
<?php } ?>
</div>
PS:當我print_r
我的內容,購物車只顯示:array()
其手段當我添加購物車,購物車不能進入購物大車。
任何人都可以解決這個問題嗎?
謝謝。
可以給我解決這個問題嗎? –
你的'insert()'函數看起來像什麼? – Marius
@marius我不明白你的意思,你可以具體說明insert()函數嗎? –