2015-03-02 36 views
1

嗨,大家好我使用codeigniter 3作爲項目。現在我需要添加購物車系統。所以我試圖使用CI的默認購物車類。 但是當我嘗試加載它通過查看它給了我一個錯誤信息

一個PHP錯誤遇到

嚴重性:注意

消息:未定義的屬性:CI_Loader :: $車

這是我的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> 

可能有人給我這樣的幫助呢? 謝謝。

回答

3

您,是因爲購物車類中已使用該名稱試圖改變

+0

OMG ..我這樣做了兩天..到處搜尋到控制器的類名購物車改爲其他名稱..但找不到答案.. 這工作隊友..謝謝! – 2015-03-02 12:48:45

+1

我仍然不被允許投票。我需要15名聲譽:( – 2015-03-02 13:07:40

+0

嗨Yas Kay Selva我親切地投了你的答案。 – 2017-07-18 17:40:43

相關問題