0

我正在使用购物车库,并在运输页面中显示数量(在文本框中)、价格、描述、小计、总计。下面是更新链接,按更新应该去控制器购物车->更新

<a href="<?php echo BASE_INDEX_URL; ?>/cart/update/<?php echo $items['rowid'];?>">Update </a>

下面是更新动作,如果我将默认数量值设置为 3,则更新购物车类(表示数量、价格、描述)

public function update($rowid)
{
    $data=$this->cart->update(array(
        'rowid'=>$rowid,
        'qty'=>3
    ));

    $this->cart->update($data);  

    redirect('cart/shipping');
}

但是我想从特定项目的运输页面中的文本字段中获取数量值并进行更新

4

2 回答 2

2

You're not passing the textbox value to the new page. You'll either need to POST data to the page via a form, or pass the value from the textbox in the url.

add this to your view:

<form action="" method="POST">
  <input type="text" name="quantity" value="" />
  <!-- OTHER FORM FIELDS HERE -->
  <input type="submit" name="submit" value="UPDATE" />
</form>

and your controller:

public function update($rowid)
{
    $data=$this->cart->update(array(
        'rowid'=>$rowid,
        'qty'=> $this->input->post('quantity');
    ));

    $this->cart->update($data);  

    redirect('cart/shipping');
}
于 2012-12-21T15:22:25.130 回答
0

我知道这已经晚了,但可能对其他人有帮助,你需要做这样的事情,

将此添加到您的视图文件中

 <?php echo form_input(array('name' =>'qty[]', 'type'=>'number','class'=>'form-control', 'style'=>'width:75px' ,'value' => $items['qty'], 'maxlength' => '3', 'size' => '5')); ?>
    <?php echo form_input(array('name' =>'rowid1[]', 'type'=>'hidden', 'value' => $items['rowid'], 'maxlength' => '3', 'size' => '5')); ?>

这在你的控制器文件中

  public function updateCart()
{
    $i = 0;
    foreach ($this->cart->contents() as $item) {

        $qty1 = count($this->input->post('qty'));
        //    print_r($qty1);
        //$i=1;
        for ($i = 0; $i < $qty1; $i++) {
            echo $_POST['qty'][$i];
            echo $_POST['rowid1'][$i];
            $data = array('rowid' => $_POST['rowid1'][$i], 'qty' => $_POST['qty'][$i]);
            $this->cart->update($data);
        }
       // $this->load->view('cart');

    }
    redirect('Shoppingcart/viewcart');
}
于 2017-04-21T07:03:38.007 回答