我有这个控制器:
<?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');
}
}
&#13;
我有使用此控制器的视图文件:
<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>
&#13;
我很抱歉我无法向您展示实际的网站,因为它不在线,但基于上述代码段可以指出视图文件或控制器中的错误导致购物车不能更新
我正在关注视频教程,但似乎我做错了什么。以下是视频:https://youtu.be/ajt_DJMS5FM?t=13m45s
答案 0 :(得分:0)
您的表单操作是购物车/更新您在控制器中添加的功能?
将表单操作更改为购物车/添加。或者写一个购物车/更新功能。
答案 1 :(得分:0)
首先将表单操作操作=&#34;购物车/更新&#34; 更改为
action="<?php echo base_url();?>cart/add" and apply die(); and test it
答案 2 :(得分:0)
在控制器中加载购物车库
if ([[self.options objectForKey:@"mediaType"] isEqualToString:@"video"]) {
self.picker.mediaTypes = @[(NSString *)kUTTypeMovie];
} else if ([[self.options objectForKey:@"mediaType"] isEqualToString:@"mixed"]) {
self.picker.mediaTypes = @[(NSString *)kUTTypeMovie, (NSString *)kUTTypeImage];
} else {
self.picker.mediaTypes = @[(NSString *)kUTTypeImage];
}