大家好我在一个项目中使用codeigniter 3。现在我需要添加一个购物车系统。因此,我尝试使用CI的默认购物车类。 但是当我尝试通过视图加载它时,它会给我一个错误消息
遇到PHP错误
严重性:注意
消息:未定义的属性:CI_Loader :: $ cart
这是我的Cart.php,它是控制器。
defined('BASEPATH') OR exit('No direct script access allowed');
class Cart extends CI_Controller {
public function __construct (){
parent::__construct();
$this->load->helper(array('url','language','form'));
}
public function index()
{
$this->load->library('cart');
$this->load->view('home/cart');
}
public function update(){
$this->load->library('cart');
$this->cart->update($_POST);
redirect(base_url().'home/cart');
}
public function add_variables(){
$this->load->library('cart');
$data = array(
array(
'id' => 'sku_123ABC',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'L', 'Color' => 'Red')
),
array(
'id' => 'sku_567ZYX',
'qty' => 1,
'price' => 9.95,
'name' => 'Coffee Mug'
),
array(
'id' => 'sku_965QRS',
'qty' => 1,
'price' => 29.95,
'name' => 'Shot Glass'
)
);
$this->cart->insert($data);
}
}
这是我的观点(cart.php)
<!DOCTYPE html>
<html>
<head>
<title>Cart<title>
</head>
<body>
<?php $this->load->view('home/top-bar'); ?>
<div id="page">
<?php $this->load->view('home/header'); ?>
<div id="center-right">
<h1>This is Cart</h1>
<?php echo form_open(base_url().'Cart/update'); ?>
<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>
<th style="text-align:right">Sub-Total</th>
</tr>
<?php $i = 1; ?>
<?php foreach ($this->cart->contents() as $items): ?>
<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
<tr>
<td><?php echo form_input(array('name' => $i.'[qty]', 'value' => $items['qty'], 'maxlength' => '3', 'size' => '5')); ?></td>
<td>
<?php echo $items['name']; ?>
<?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>
<p>
<?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?>
<strong><?php echo $option_name; ?>:</strong> <?php echo $option_value; ?><br />
<?php endforeach; ?>
</p>
<?php endif; ?>
</td>
<td style="text-align:right"><?php echo $this->cart->format_number($items['price']); ?></td>
<td style="text-align:right">$<?php echo $this->cart->format_number($items['subtotal']); ?></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td colspan="2"> </td>
<td class="right"><strong>Total</strong></td>
<td class="right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</table>
<p><?php echo form_submit('', 'Update your Cart'); ?></p>
</div>
</div>
<?php $this->load->view('home/footer'); ?>
</body>
</html>
有人可以给我一个帮助吗? 谢谢。
答案 0 :(得分:3)
您必须将控制器类名称购物车更改为其他名称,因为购物车类已使用该名称尝试更改
答案 1 :(得分:0)
$ autoload ['libraries'] = array('database','email','session','cart');
我的问题是通过在autoload.php文件中添加购物车来解决