Search code examples
codeignitermodelsubdirectory

Codeigniter does not find model files in models subfolders


Saving a model in a sub-folder such as models/cronjobs/Dbsconnection_model.php I always get a "Message: Unable to locate the model you have specified: Dbsconnection_model" error when i load it with

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

    require('application/config/CronJobs/CronjobsConfig.php');

    **$this->load->model('cronjobs/dbsconnection_model');**

    [......]

If i take the same model in the upper folder there are no troubles; in other words, this function

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

does not trigger any error if the relative file is copied in the main models folder too. I tried also several combinations for the subfolder name:

  • cronjobs
  • Cronjobs
  • CronJobs

changing it both in the filesystem and in the loading function. Any ideas?


Solution

  • You need to capitalize the first letter of your model class and it will work.

    So you can still call it like

    $this->load->model('cronjobs/dbsconnection_model');
    

    But the model file itself needs to start with a capital letter.

    For example

    application/models/cronjobs/Dbsconnection_model.php