我正在嘗試更新我的購物車(通過客戶更改銷售產品的數量),並使用購物車庫。當我提交更新按鈕時,頁面將按照我的意願重定向,但不會更新並顯示以前的值,並且我不會收到任何錯誤。我的代碼有什麼問題?在Codeigniter v2.2中更新購物車庫
我的更新控制器代碼
public function update($in_cart = null){
$data= $_POST;
$this->cart->update($data);
//show cart page
redirect ('cart','refresh');
}
和我的視圖代碼是
<form action="cart/update" method="post">
<table cellpadding="6" cellspacing="1" style= "width: 100%" border="0" >
<tr>
<th>QTY</th>
<th>item description</th>
<th style="text-align: right">Item Price</th>
</tr>
<?php $i=1; ?> <!-- $i=1 is a counter -->
<?php foreach ($this->cart->contents() as $items) : ?>
<input type="hidden" name="<?php echo $i.'[rowid]'; ?>" value="<?php echo $items['rowid'];?> "/>
<tr>
<td id="cart-qty"><input type="text" name="<?php echo $i.'[qty]'; ?>" value="<?php echo $items['qty'];?>" maxlength="3" size="5"> </td>
<td><?php echo $items ['name'];?></td>
<td style="text-align: right"><?php echo $this->cart->format_number($items['price']);?> </td>
</tr>
<?php $i++ ; ?>
<?php endforeach; ?>
<tr>
<td></td>
<td class="right"><strong>Total</strong></td>
<td class="right" style="text-align: right">$<?php echo $this->cart->format_number($this->cart->total());?></td>
</tr>
</table>
<br>
<p><button class="btn btn-default" type="submit">Update Cart</button>
<a class="btn btn-default" href="cart">go to cart</a></p>
</form>
我只是想你的代碼,但沒有奏效。我的代碼有兩個錯誤 – Mehdi
嘗試編輯我的新代碼。 –
仍然與他們有一個錯誤,我想我自己的控制器應該是對的,因爲我沒有任何錯誤,可能這個問題是從我的角度來看的。 – Mehdi