2017-04-25 27 views
2

我有这样的控制器:车块不更新笨

<?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'); 
 
    } 
 
    }

我有使用这种控制器的视图文件:

<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>

我道歉我无法向您展示实际的网站,因为它不在线,但基于上述片段可以指出视图文件或控制器中导致购物车不更新的错误?

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

+0

车库您没有** **更新方法**购物车**控制器,你的意思是不加入? –

回答

0

你的表单动作是购物车/更新你的控制器中的功能是添加?

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

+0

我尝试过,但仍然没有运气。 –

+0

跳过这里https://youtu.be/ajt_DJMS5FM?t=925它解释了控制器功能。 – Ryan

+0

是的,我现在一遍又一遍地看着它,这就是为什么它没有意义。我还添加了购物车更新功能,但受同一问题影响。 –

0

窗体动作首先改变行动= “购物车/更新”

action="<?php echo base_url();?>cart/add" and apply die(); and test it 
+0

我在哪里申请die(); ? –

+0

你的控制器添加()函数.. –

+0

好吧,所以我申请了die();在数组之后,这是正确的吗? –

0

负载控制器

$this->load->library('cart'); 
+0

没有运气,谢谢。 –