我目前正试图做一个项目的基础上,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条答案
按热度按时间7gs2gvoe1#
添加以下代码
应用程序/config/ruotes.php
产品控制器-更新