gpt4 book ai didi

javascript - 购物车 block 未更新 codeigniter

转载 作者:行者123 更新时间:2023-12-01 05:21:09 24 4
gpt4 key购买 nike

我有这个 Controller :

<?php
class Cart extends CI_Controller{
public $paypal_data = '';
public $tax;
public $shipping;
public $total = 0;
public $grand_total;

/*
*Cart Index
*/
public function index(){
//Load view
$data['main_content'] = 'cart';
$this->load->view('layouts/main', $data);
}

/*
*Add To Cart
*/
public function add(){
//Item data
$data = array(
'id'=> $this->input->post('item_number'),
'qty'=> $this->input->post('qty'),
'price'=> $this->input->post('price'),
'name'=> $this->input->post('title'),
);
//print_r($data);die();

//Insert Into cart-block
$this->cart->insert($data);

redirect('products');
}
}

我有使用此 Controller 的 View 文件:

<div class="cart-block">
<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; ?>
<?php foreach ($this->cart->contents() as $items) : ?>
<input type="hidden" name="<?php echo $i. '[rowid]'; ?>" value="<?php echo $items['rowid']; ?>" />
<tr>
<td><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>
</div>
<div class="panel panel-default panel-list">
<div class="panel-heading panel-jeading-dark">
<h3 class="panel-title">
Categories
</h3>
</div>

<!--List group -->
<ul class="list-group">
<?php foreach(get_categories_h() as $category) : ?>
<li class="list-group-item"><a href="<?php echo base_url(); ?>products/category/<?php echo $category->id; ?>"><?php echo $category->name; ?></a></li>
<?php endforeach; ?>
</ul>

很抱歉,我无法向您展示实际的网站,因为它不在线,但根据上面的代码片段,是否可以指出 View 文件或 Controller 中导致购物车无法更新的错误?

我正在观看视频教程,但似乎我做错了什么。这是视频:https://youtu.be/ajt_DJMS5FM?t=13m45s

最佳答案

您的表单操作是购物车/更新您在 Controller 中的功能是添加吗?

将表单操作更改为购物车/添加。或者编写一个购物车/更新功能。

关于javascript - 购物车 block 未更新 codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43600577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com