Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter 在购物车上添加产品_Codeigniter_E Commerce_Shopping Cart - Fatal编程技术网

Codeigniter 在购物车上添加产品

Codeigniter 在购物车上添加产品,codeigniter,e-commerce,shopping-cart,Codeigniter,E Commerce,Shopping Cart,朋友们,我正在开发一个电子商务网站(使用Codeigniter) 在客户填写产品数量并单击“购买”后,只有“数量”字段的产品才能在购物车中填写。你能帮我吗 HTML: <form> <ul class="products-list"> <li class="product"> <input type="hidden" class="product_id" value="1"> <span class="

朋友们,我正在开发一个电子商务网站(使用Codeigniter)

在客户填写产品数量并单击“购买”后,只有“数量”字段的产品才能在购物车中填写。你能帮我吗

HTML:

<form>
<ul class="products-list">
    <li class="product">
        <input type="hidden" class="product_id" value="1">
        <span class="product-name">Product 1</span>
        <span class="product-value">$ 100</span> 
        <span>Qnt. <input type="text" class="quantity"></span> 
    </li>
        <li class="product">
        <input type="hidden" class="product_id" value="2">
        <span class="product-name">Product 2</span>
        <span class="product-value">$ 100</span> 
        <span>Qnt. <input type="text" class="quantity"></span> 
    </li>
</ul>
<button>Buy</button>
</form>
$.ajax({
    url: '/cart/add/'+product_id+'/'+quantity,
    type: 'GET',
    success: function( data ){
        if ( data != false ) {
            window.location.reload();
        }
    }
});
public function addItem( $product_id, $quantity){ 
    $product = $this->Produto_model->getById($product_id); 
    $this->carrinho->setItem($product, $quantity); 
    echo json_encode($this->carrinho); 
}  

我的PHP代码:

<form>
<ul class="products-list">
    <li class="product">
        <input type="hidden" class="product_id" value="1">
        <span class="product-name">Product 1</span>
        <span class="product-value">$ 100</span> 
        <span>Qnt. <input type="text" class="quantity"></span> 
    </li>
        <li class="product">
        <input type="hidden" class="product_id" value="2">
        <span class="product-name">Product 2</span>
        <span class="product-value">$ 100</span> 
        <span>Qnt. <input type="text" class="quantity"></span> 
    </li>
</ul>
<button>Buy</button>
</form>
$.ajax({
    url: '/cart/add/'+product_id+'/'+quantity,
    type: 'GET',
    success: function( data ){
        if ( data != false ) {
            window.location.reload();
        }
    }
});
public function addItem( $product_id, $quantity){ 
    $product = $this->Produto_model->getById($product_id); 
    $this->carrinho->setItem($product, $quantity); 
    echo json_encode($this->carrinho); 
}  
像这样试试

HTML:


你的问题是什么?什么有效,什么无效?哪里出错了?好的,我在routes.php文件中做了什么?当前看起来是这样的:$route['cart/add/(:num)/(:num)']=“front/products/addItem/$1/$2”<代码>$route['cart/add/']=“front/products/addItem/”