Codeigniter购物车已更新

时间:2018-10-04 13:26:15

标签: codeigniter shopping-cart shopping

我对Codeigniter购物车更新有疑问。我正在测试这堂课。我面临的问题是,当我尝试发布数据时,rowid被当作数组,而数量作为普通的发布变量。

这是html:

<div class="wrap">
  <div class="overflow overflow--1">
    <div class="overflow__wrap">
      <div class="overflow__content">
        <button>Scroll horizontally</button>
        <button>Horizontal scroll visible under</button>
        <button>Horizontal scroll visible under</button>
        <button>Horizontal scroll visible under</button>
      </div>
    </div>
  </div>
  <div class="overflow overflow--2">
    <div class="overflow__wrap">
      <div class="overflow__content">
        <button>Horizontal scroll hidden</button>
        <button>Yes, really</button>
        <button>Yes, really</button>
        <button>Yes, really</button>
      </div>
    </div>
  </div>
</div>
<br/><br/><br/>
<p>Snippet end</p>

这是我的最终控制器UpdateCart()代码,它的工作方式如下:

<?php echo form_open(base_url('ShoppingCart/UpdateCart')); ?>
                    <table class="table">
                        <thead>
                            <tr>
                                <th class="cart-romove item">Remove</th>
                                <th class="cart-description item">Image</th>
                                <th class="cart-product-name item">Product Name</th>
                                <th class="cart-edit item">Edit</th>
                                <th class="cart-qty item">Quantity</th>
                                <th class="cart-sub-total item">Subtotal</th>
                                <th class="cart-total last-item">Grandtotal</th>
                            </tr>
                        </thead>
                        <!-- /thead -->

                        <tbody>
                            <?php
                            $items = $this->cart->contents ();
                            // echo count ( $items );
                            $i = 1;

                            foreach ( $items as $item ) {
                                echo form_hidden ( $i . '[rowid]', $item ['rowid'] );

                                $this->load->view ( 'pages/tpl/products/product-listing-cart', array (
                                        'item' => $item,
                                        'i' => $i
                                ) );
                                $i ++;

                            }
                            ?>

                        </tbody>
                        <!-- /tbody -->
                        <tfoot>
                            <tr>
                                <td colspan="7">
                                    <div class="shopping-cart-btn">
                                        <span class=""> <a href="<?= $this->agent->referrer(); ?>"
                                            class="btn btn-upper btn-primary outer-left-xs">Continue
                                                Shopping</a> 

                                                <?php echo form_submit('', 'Update Shopping Cart');?>
                                                <a href="<?=base_url('ShoppingCart/UpdateCart'); ?>" class="btn btn-upper btn-primary pull-right outer-right-xs">Update shopping cart</a>
                                        </span>
                                    </div> <!-- /.shopping-cart-btn -->
                                </td>
                            </tr>
                        </tfoot>
                    </table>
                    <!-- /table -->

我想知道是否有更好的方法来实现上述目标?我尝试过将发布数据填充到单个循环中的数据数组中,但是在所有情况下都存在警告/错误。

有什么建议/见解吗?

谢谢

0 个答案:

没有答案