2015-04-02 65 views
0

請幫助我。我試圖解決它,但我的代碼中有什麼問題?這是我第一次遇到這個錯誤。我真的需要幫助,請。致命錯誤:調用未定義的方法codeigniter

這是我得到的錯誤:

Fatal error: Call to undefined method supp_model::getsuppid() in C:\wamp\www\minimart\application\controllers\minimart.php on line 19 

這是我的圖書館:

class minimart extends CI_controller { //myclass 


function __construct() 
    { 

    parent::__construct(); 
    } 



    function supplier() 
    { 
     $this->load->model('supp_model'); 
     $id = $this->uri->segment(3); 
     $mini['allrecords']= $this->supp_model->getsuppid($id); //this line give me an error 
     $this->load->view('view_supplier.php', $mini); 
    } 

我的模型:

class supp_model extends CI_Model { 



    function getsuppid($id) //the function exist 
    { 
     $this->db->select('*'); 
     $this->db->from('supplier_table'); 
     $this->db->where('supplier_code ', $id); 
     $q = $this->db->get(); 
     $result = $q->result(); 
     return $result; 
    } 

} 
+0

首先,你需要做第一班級名稱**大寫字母**它應該像**班級Minimart **和** c lass Supp_model ** – 2015-04-02 04:25:36

+0

將構造函數添加爲{parent :: __ construct(); } – Eranda 2015-04-02 04:39:26

+0

謝謝Advise @NarendraSisodia我只是重命名:) – 2015-04-02 05:54:54

回答

1
function __construct() { 
     // Call the Model constructor 
     parent::__construct(); 
     $this->db = $this->load->database('default', true); 
    } 
function supplier() 
    { 
     $this->load->model('supp_model',true); 
     $id = $this->uri->segment(3); 
     $mini['allrecords']= $this->supp_model->getsuppid($id); 
     $this->load->view('view_supplier.php', $mini); 
    } 
+0

謝謝!這麼多@靈魂:D現在我可以繼續;) – 2015-04-02 05:54:03

+0

@MilbhenBars接受答案,並upvote,如果它幫助你 – Ghostman 2015-04-02 06:11:34

相關問題