代码点火器无法从购物车中检索数据



我正在用代码点火器做一个项目。在这里,我已将数据插入购物车代码点火器。但是我无法从查看文件中的购物车中检索数据,也尝试了下面给出的一些代码,我是一个尝试学习代码的新手,因此请在这方面帮助我。控制器代码:-

class Cart extends CI_Controller{
//put your code here
public function __construct() {
parent::__construct();
$this->load->model('Cart_model');
$this->load->library('cart');

}
public function add_to_cart(){
$product_id= $this->input->post('product_id',true);
$qty= $this->input->post('qty',true);
$this->load->model('Cart_model');
$category_info= $this->Cart_model->select_product_info_by_product_id($product_id);
$data = array(
'id'      =>$category_info->product_id,
'qty'     => $qty,
'price'   => $category_info->product_price,
'name'    => $category_info->product_name,
'options' => array('image' => $category_info->product_image)
);
$this->cart->insert($data);
$this->load->view('pages/cart_view',$data); ;
}
}

型号:-

class Cart_model extends CI_Model{
//put your code here
public function select_product_info_by_product_id($product_id) {
$category_info= $this->db->select('*')
->from('tbl_product')
->where('product_id',$product_id)
->get()->row();
return $category_info;
} 
}

查看代码:-

<div class="table-responsive cart_info">
<table class="table table-condensed">
<thead>
<tr class="cart_menu">
<td class="image">Item</td>
<td class="description"></td>
<td class="price">Price</td>
<td class="quantity">Quantity</td>
<td class="total">Total</td>
<td></td>
</tr>
</thead>
<tbody>
<?php $contents=$this->cart->contents();
print_r($contents);
foreach ($contents as $v_contents){

?>  
<tr>
<td class="cart_product">
<a href=""><img src="images/cart/one.png" alt=""></a>
</td>
<td class="cart_description">
<h4><a href=""><?php echo $v_contents['name']?></a></h4>
</td>
<td class="cart_price">
<p><?php echo $v_contents['price']?></p>
</td>
<td class="cart_quantity">
<div class="cart_quantity_button">
<a class="cart_quantity_up" href=""> + </a>
<input class="cart_quantity_input" type="text" name="quantity" value="<?php echo $v_contents['qty']?>" autocomplete="off" size="2">
<a class="cart_quantity_down" href=""> - </a>
</div>
</td>
<td class="cart_total">
<p class="cart_total_price"><?php echo $v_contents['subtotal']?></p>
</td>
<?php } ?>
</tr>
</tbody>
</table>
</div>

配置.php

$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['sess_use_database']=TRUE;
$config['sess_table_name']      = 'ci_sessions';

购物车.php

public $product_name_rules = '[:print:]';

在这里,我在上面尝试过,但无法检索视图中的购物车数据。请在这方面帮助我。

购物车.php

公共 $product_名称_安全 = TRUE;

取代

public $product_name_safe = FALSE;

相关内容

  • 没有找到相关文章

最新更新