0

Having a very strange issue with an error on a codeigniter site.

Fatal error: Call to undefined method Document::get_by_module()

The line of code causing this (in a controller) is:

$this->document_type->get_by_module('module1');

The constructor of the controller:

function __construct(){
    parent::__construct();
    $this->load->model('document','document_type');
}

The document_type class looks like this

class Document_type extends CI_Model {
    function Document_type () {
        parent::__construct();

    }       
    function get_by_module($prefix) {
        // code 
    }
}

The main issue I'm seeing is that it's saying Document:: is the class, but it should be Document_type. I see no reason that it should be looking in the document class for that function.

If I remove loading of the 'document' class from the controller constructor, the error goes away (but other things break).

Not sure how something like that could be happening.

4

1 回答 1

1

看起来您正在加载错误的模型文件。线

$this->load->model('document','document_type');

意思是这样的:给我找一个名为“文档”的模型,创建一个实例并放在$this->document_type. (见第四个例子

看起来您有一个Document模型,因此加载成功,但是如果您不想重命名放在$this(控制器实例)下的实例,则不应使用该$this->load->model()行中的第二个参数。

简单地写$this->load->model('document_type');

于 2012-09-25T20:39:29.680 回答