0

エラーが発生します

Fatal error: Call to a member function retrieve_products() on a non-object

コントローラは次のとおりです。

<?php   
class Cart extends CI_Controller { // Our Cart class extends the Controller class  

   public function _construct()  
   {  
       parent::_construct(); // We define the the Controller class is the parent.  
       $this->load->model('Cart_model'); // Load our cart model for our entire class  
   }

   function index()  
   {  
      $data['products'] = $this->cart_model->retrieve_products(); // Retrieve an array with all products  
   }
}

モデルは次のとおりです。

<?php   
class Cart_model extends CI_Model {

    function retrieve_products(){  
        $query = $this->db->get('products'); // Select the table products  
        return $query->result_array(); // Return the results in a array.
    }             
}
4

3 に答える 3

1

私はあなたの電話を言いたい

$data['products'] = $this->cart_model->retrieve_products();

する必要があります:

$data['products'] = $this->Cart_model->retrieve_products();

つまり、cart_modelの大文字の「C」

于 2012-07-03T21:10:26.050 に答える
1

異なるバージョン(1.7.2を使用しています)を使用している可能性がありますが、モデルを宣言するためにCI_表示されません。私の作業コードには、次のものと同等のものがあります。

class Cart_model extends Model

また、クラスは大文字にする必要があります。

$this->Cart_model->retrieve_products();

(それ以外の)

$this->cart_model->retrieve_products();
于 2012-07-03T19:45:35.750 に答える
0

codeigniterがそれをクラスコンストラクターではなく関数と見なし、モデルの読み込みがその関数のみに制限されているのは、それでは_constructなく、構文関数をスペルミスしたタイプミスだと思います。__construct

于 2012-07-06T08:05:18.437 に答える