2015-10-09 82 views
2

我正在制定一個由[easyappointments][1]提供的日曆計劃,但現在我昨天堅持在這個錯誤。在主網頁users.php我已經添加了以下內容:

<?php 
    require_once("application/models/impostazioni_model.php"); 

    $this->load->model('impostazioni_model'); 
    $this->impostazioni_model->load_colours(); 
?> 

require_once找到正確的文件impostazioni_model.php但是當我在頁面中輸入users.php

我看到這個錯誤:

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

在這line:$this->impostazioni_model->load_colours();

這個類別impostazioni_model.php我這樣的內容:

<?php if (! defined('BASEPATH')) exit('Direct execution not allowed.'); 

class Impostazioni_Model extends CI_Model 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
    } 


    public function load_colours() 
    { 
     echo "print"; 
    } 

} 

?> 

我跟着codeigniter文檔,特別是類模型必須是大寫字母,所以我不知道我錯了什麼。有人可以幫助我?

+0

的http:// stackov erflow.com/questions/12769982/reference-what-does-this-error-mean-in-php – Linus

+0

您使用的是哪個版本的CI? – Saty

+0

我使用的是3.0.0版本 – Dillinger

回答

1

在控制器

路徑 - application/controllers

<?php 

if (!defined('BASEPATH')) 
    exit('No direct script access allowed'); 

class Admin extends CI_Controller { 

    function __construct() { 
     parent::__construct(); 
     $this->load->model('impostazioni_model'); //this will show "Print" word on browser. 
    } 

    function index() { 

    $this->impostazioni_model->load_colours(); 

    } 

} 

在型號

路徑 - application/model

<?php 

    if (!defined('BASEPATH')) 
     exit('No direct script access allowed'); 

    class Impostazioni_model extends CI_Model { 

     function __construct() { 
      parent::__construct(); 
     } 

     function load_colours() { 
      echo "print"; 
     } 
    } 
+0

有一個問題:你說我在我的文件夾「應用程序/控制器」中的「應用程序/控制器」,我必須編輯哪個文件? 「應用程序/模型」上的同樣的事情我有「應用程序/模型」我不知道哪個文件必須編輯。 – Dillinger

+0

已編輯。現在檢查 –

+0

好的,但在控制器文件夾中,我沒有文件「admin.php」,其中文件位於類「Admin」? 模型「impostazioni」必須在文件users.php中調用,該文件沒有任何類並且不能有類。原因是混合了html,php和ajax請求。這是我的「user.php」文件: http://pastebin.com/JA9QHmZd 和位於:root/application/controllers – Dillinger