Codeigniter PHP Model Access "Unable to Locate the Model You Have Specified"

CodeIgniter PHP Model Access Unable to locate the model you have specified

When creating models, you need to place the file in application/models/ and name the file in all lowercase - like logon_model.php

The logon_model.php should contain the following:

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

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

Now, what you can do, to test if your application model is reachable, is to try opening it in the browser - like so:

http://example.org/application/models/logon_model.php

If you see the text No direct script access allowed it means you hit the right file (if you are in doubt, try writing something else in the exit() in the first line).

Secondly, for loading the model in your controllers, you should be able to do like this:

public function index()
{

$this->load->model('logon_model');
...

}

If everything above checks out as expected I would begin looking at file permissions and/or possibly symlinks if you are using any.

CodeIgniter 3 Unable to locate the model you have specified

Your git may be configured to ignore case changes in file names. The effect of this is: any local changes to a filename of a file that has already been deployed (i.e. is only being modified) are not mirrored on the remote repository (heroku).

For example, if you first deployed a file with the name users_model.php all lowercase. Even if you change the local version of the file to Users_model.php with the 'U' capitalized, the remote won't mirror this change.

How to solve it: to tell git to update filename case changes, run the following command:

git config core.ignorecase false

Thanks to @Kamram for making me figure this out and @FeanDoe for suggesting that I answer the question.

unable to locate the model you have specified codeigniter

You need to rename your model file from user_model.php to User_model.php In windows wampp or xampp, case doesn't matter, but your production environment has got to be on linux and that is case sensitive, that's why you are getting the errors.

Unable to locate the model you have specified in CodeIgniter:

Your model file name must be ucfirst

Register_model.php

Codeigniter: unable to locate the model

After some discussion in the comments, the final answer is that the call to load->model('dashboard_model') must have the first letter of the class name capitalized per the documentation.

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

The reason it worked on Windows and not on Linux is because Windows file system is not case sensitive (normally). In general, when developing locally on Windows and deploying to a *nix environment, when it works on the local and not production, the first thing you should check is something not being the correct case.

CI Model Access - Unable to locate the model you have specified when model name is specified in lower case letters

When creating a model on codeigniter

classes and file names should have there first letter as upper case this also applies for controllers and libraries etc.

Home_model.php

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

public function some_function() {

}
}

How to load model on controller example only

class Welcome extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('home_model');
// Or In a subfolder application / models / subfoldername
$this->load->model('subfoldername/home_model');
}

public function index() {
$data['results'] = $this->home_model->some_function();
$this->load->view('welcome_message', $data)
}

}


Related Topics



Leave a reply



Submit