Justin Erswell Justin Erswell - 2 months ago 35
PHP Question

Codeigniter 3 - Unable to locate the model you have specified

I am aware of the other questions on the platform for this issue however I am having a very unusual issue with this.

I have a model

Company_Model.php
which is being autoloaded in the
autoload.php
and the Class is built like this:

Class Company_Model extends CI_Model {

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

public function foo()
{
echo 'bar';
}
}


However I am still getting this error when I load the page:

Codeignter 3 - Unable to locate the model you have specified

I am running on Apache 2, PHP 5.5.9 on Ubuntu 14.04, I cannot find an error log for this issue and now I am baffled, any help would be gratefully recieved.

I have check the uppercasing and all of the other tips from StackOverflow but still no joy.

Edit



Auto load code

$autoload['model'] = array('company_model');

Answer

When you use codeigniter 3 you have to make sure your class names and file names only have the first letter upper case as explained here

Class Naming Style Guide

Filename Style Guide

<?php

class Company_model extends CI_Model {

}

And file name then should be Company_model.php

$autoload['model'] = array('company_model');

If in sub folder

models > sub folder > Company_model.php

$autoload['model'] = array('subfolder/company_model');

If need to call it on controller only

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

$this->company_model->function();

Sub folder

$this->load->model('subfolder/company_model');

$this->company_model->function();