javascript - 购物车 block 未更新 codeigniter

标签 javascript php jquery codeigniter

我有这个 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/

相关文章:

javascript - Ractive 和数组,数据未更新

php - 验证在网站上输入的用户名密码与MySQL数据库上的密码

javascript - BackboneJS - 将类添加到 <li> 元素的 <a href>

javascript - x秒后显示一个div,y秒后显示另一个div

javascript - 从 iOS/Android 上的网络应用程序调用 native 日期选择器

php - 选择实体假设相关实体不存在

jquery - Bootstrap 选项卡事件状态在 ScrollSpy 中不起作用

Jquery 阅读更多链接以添加类

javascript - 主干js : the collection initialize in view module have only one model

php - PHP PDO 的 Mysql 转义 % 和 _