Justin Erswell
Justin Erswell

Reputation: 708

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');

Upvotes: 1

Views: 32396

Answers (3)

Rahul Mishra
Rahul Mishra

Reputation: 1

Try Changing the class name Company_Model to Company_model and also change your file name Company_Model.php to company_model.php

Upvotes: 0

MDF
MDF

Reputation: 1343

Make sure your class name and file name should be same and first Letter should be Capital

Example

class Login extends CI_Model{
//some code
}

above code, you can see the class Login first letter is capital.same name you have save of your model file name like Login.php in the model directory of your project folder

Upvotes: 0

user4419336
user4419336

Reputation:

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();

Upvotes: 13

Related Questions