CodeIgniter添加到购物车错误404

时间:2018-04-21 23:54:41

标签: php html css mysql codeigniter

我目前正在尝试根据构建购物车的YouTube教程进行项目,但每当我点击添加到购物车按钮时,我都会收到错误404:找不到页面。

产品视图

<div class="col-md-4 product">
    <div class="product-price"><?php echo $product->price; ?></div>
        <a href="<?php echo base_url(); ?>products/details/<?php echo $product->id; ?>">
            <img src="<?php echo base_url(); ?>images/<?php echo $product->image; ?>" />
        </a>
        <div class="product-name"><br>
            <?php echo $product->name; ?>
        </div>
        <div class="product-add">
            <form method="post" action="<?php echo base_url(); ?> cart/add">
                QTY: <input class="qty" type="text" name="qty" value="1" />
                <input type="hidden" name="item_number" value="<?php echo $product->id; ?>"/>
                <input type="hidden" name="price" value="<?php echo $product->price; ?>"/>
                <input type="hidden" name="name" value="<?php echo $product->name; ?>"/>
                <button class="btn btn-primary" type="submit">Add To Cart</button>
            </form>

        </div>          
</div>

产品控制器

<?php
class Products extends CI_Controller{
public function index(){
    //get all products
    $data['products'] = $this->Product_model->get_products();

    //load view
    $data['main_content'] = 'products';
    $this->load->view('layouts/main', $data);
}

public function details($id){
    //get product details from the model
    $data['product'] = $this->Product_model->get_product_details($id);

    //load view
    $data['main_content'] = 'details';
    $this->load->view('layouts/main', $data);
}
}

1 个答案:

答案 0 :(得分:0)

添加以下代码

<强>应用/配置/ ruotes.php

<input type='radio' name='rad' value='0'> 0
<input type='radio' name='rad' value='1'> 1
<input type='radio' name='rad' value='2'> 2

<div id='team0' class='rgtside'>team 0</div>
<div id='team1' class='rgtside'>team 1</div>
<div id='team2' class='rgtside'>team 2</div>





<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

产品控制器 - 更新

$route['cart/add'] = 'products/addtocart';