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.
Looks like you are loading in the wrong model file. The line
means something along the lines of: Find me a model named “Document” create an instance and put under
$this->document_type. (see the 4th example)Looks like you have a
Documentmodel so the load succeeds, but if you don’t want to rename your instance put under the$this(controller instance) you shouldn’t use the second parameter in the$this->load->model()line.Simply write
$this->load->model('document_type');