CodeIgniter -

3 Cevap php

THE SUMMARY:

Ben ... / index.php / ürün aradığınızda, ben alırsınız:

Fatal error: Call to a member function get_prod_single() on a non-object in /var/www/sparts/main/controllers/product.php on line 16

Soruna Hattı 16'dır:

$data['pn_oem'] = $this->product_model->get_prod_single($product_id);

Ben bu çalışan bir nesnenin nasıl bilmiyorum gibi görünüyor. Bana yardımcı olabilir misiniz?

THE CODE:

Benim /Models klasöründe ben product_model.php:

<?php
class Product_model extends Model {

    function Product_model()
    {
        parent::Model();
    }

    function get_prod_single($product_id)
    {
        //This will be a DB lookup ...
        return 'foo';  //stub to get going
    }   
}
?>

Benim /controllers klasöründe ben product.php:

<?php
class Product extends Controller {

    function Product()
    {
        parent::Controller();
    }

    function index()  {

      $this->load->model('Product_model');

      $product_id = 113; // will get this dynamically

      $data['product_id'] = $product_id;
      $data['pn_oem'] = $this->product_model->get_prod_single($product_id);

      $this->load->view('prod_single', $data);
    }
}
?>

3 Cevap

Bence bu $ this-> load-> modeli ('Product_model'); product_model isim Product_model bir model oluşturmak ve olmayacaktır ... PHP harf duyarlıdır.

Sadece değiştirmek:

$this->load->model('Product_model');

için:

$this->load->model('product_model');

Yükleyici geçirilen ad dosya adını başvuran gibi görünüyor.

CI model isimleri harf duyarlıdır, bu yüzden yerine "Product_model" nin "product_model" iş yapacak. Eğer bir takma ad çeşit ayarlayabilirsiniz isterseniz Doğru hatırlıyorsam, bir şey gibi gider

$this->load->model('product_model', 'Product_model');

bu da çalışmış olurdu.

EDIT: slight typo in the alias. fixed