尝试试用购物车库,它在CI3中没有mx hmvc的情况下正常工作。但是一旦我插入MX hmvc文件(即在应用程序/核心文件夹中的MY_Loader.php和MY_Router.php以及在third_party文件夹中的MX文件夹),它就会抛出错误
Severity: Notice
Message: Undefined property: Welcome::$Session
Filename: MX/Loader.php
Line Number: 171
我甚至没有尝试使用codeigniter的默认控制器和视图。 我修改过的codeigniter控制器welcome.php如下所示
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->helper('form');
$this->load->helper('url');
// Load the cart library to use it.
$this->load->library('cart');
// Assuming this is the products from our database
$data['products'] = array(
array(
'id' => 'sku_888',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'xxx', 'Color' => 'White')
),
array(
'id' => 'sku_888',
'qty' => 1,
'price' => 39.95,
'name' => 'T-Shirt',
'options' => array('Size' => 'xx', 'Color' => 'green')
),
array(
'id' => 'sku_777',
'qty' => 1,
'price' => 9.95,
'name' => 'Coffee Mug'
),
array(
'id' => 'sku_666',
'qty' => 1,
'price' => 29.95,
'name' => 'Shot Glass'
)
);
// Insert the product to cart
if ($this->input->get('id') != '' && array_key_exists($this->input->get('id'), $data['products']))
{
$this->cart->insert($data['products'][$this->input->get('id')]);
}
// Lets update our cart
if ($this->input->post('update_cart'))
{
unset($_POST['update_cart']);
$contents = $this->input->post();
foreach ($contents as $content)
{
$info = array(
'rowid' => $content['rowid'],
'qty' => $content['qty']
);
$this->cart->update($info);
}
}
$this->load->view('welcome_message', $data);
}
}
和默认的codeigniter视图welcome_message.php,我修改如下
<b>Products</b>
<table width="100%" border="1">
<tr>
<td width="37%">ID</td>
<td width="30%">Name</td>
<td width="16%">Price</td>
<td width="16%"> </td>
</tr>
<?php $product_array_index = 0;?>
<?php foreach($products as $product):?>
<tr>
<td><?php echo $product['id'];?></td>
<td>
<?php
echo $product['name'] ;
if (array_key_exists('options', $product)) {
echo '<hr>';
foreach ($product['options'] as $key => $value)
{
echo '<strong>' . $key . '</strong> : '. $value . '<br/>';
}
}
?>
</td>
<td><?php echo $product['price'];?></td>
<td><a href="?id=<?php echo $product_array_index;?>">Add to Cart</a></td>
</tr>
<?php $product_array_index ++;?>
<?php endforeach;?>
</table>
<hr>
<b>Your Cart</b>
<?php echo form_open(base_url()); ?>
<table cellpadding="6" cellspacing="1" style="width:100%" border="1">
<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" align="right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</table>
<p><?php echo form_submit('update_cart', 'Update your Cart'); ?></p>
如何让它发挥作用?