2

I am having a real funny issue loading the model on my AWS ec2 instance.

AWS ec2 Instance is working fine and runs php 5.6 like my localhost.

on localhost the model works perfectly fine, I upload the file to my webpage, and it breaks with the following error:

An uncaught Exception was encountered

Type: RuntimeException

Message: Unable to locate the model you have specified: Dashboard_model

Filename: /var/www/html/poe_dashboard/system/core/Loader.php

Line Number: 314

Backtrace:

File: /var/www/html/poe_dashboard/application/controllers/Dashboard.php
Line: 7
Function: __construct

File: /var/www/html/poe_dashboard/index.php
Line: 292
Function: require_once

To me this does not make sense because if it works locally, with the same PHP version, what is the problem on live?

Class names and file names are all correct according to the codeigniter standards.

here is the link: http://www.haddad.design/poe_dashboard/

If i don't choose to load my model at all and just run the controller to load the view, it loads as it normally should.

Any suggestions?

Controller:

class Dashboard extends CI_Controller {

function __construct() {
    parent::__construct();
    $this->load->model('dashboard_model');
}

Filename:

dashboard_model.php

Model:

class Dashboard_model extends CI_Model {

public function __construct() {
    parent::__construct();
}
thechrishaddad
  • 6,523
  • 7
  • 27
  • 33
  • Is your localhost windows? If so, Windows does not enforce case sensitivity like Linux does. `dashboard_model` !== `Dashboard_model` on *nix boxes. Also, try renaming your file to match the class name as far as case goes. – Jeremy Harris Dec 18 '15 at 01:56
  • I am running it on my windows 10 machine, so how could I make this work on my aws then? – thechrishaddad Dec 18 '15 at 02:01
  • On Windows, it won't complain about the case difference and will find the file. On Linux, `dashboard_model` and `Dashboard_model` are completely different. To make it work, make all instances of that string be the exact same, including file name. – Jeremy Harris Dec 18 '15 at 02:02
  • hmm i tried to make the model class name all lowercase the same way I am calling everything else, but still no success. – thechrishaddad Dec 18 '15 at 02:08
  • 1
    They need to be named following code igniters standards (https://ellislab.com/codeigniter/user-guide/general/models.html#anatomy). So `Dashboard_model` is what it should be called consistently across the board. – Jeremy Harris Dec 18 '15 at 02:10
  • Actually reading a little closer, `The file name will be a lower case version of your class name`. So the issue was your call to `load->model()` had a lowercase `d`. – Jeremy Harris Dec 18 '15 at 02:11
  • Yep, got it, thanks champ! – thechrishaddad Dec 18 '15 at 02:14

3 Answers3

4

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.

Community
  • 1
  • 1
Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
0

Solution I have done by this way: I was calling earlier

$this->load->model('**Users_Model**');

now I am calling

$this->load->model('**users_model**');

I have also renamed the model file like: /projectname/codeigniter/application/models/Users_model.php and code

defined('BASEPATH') OR exit('No direct script access allowed');

class Users_model extends CI_Model{
    public function __construct(){
        $this->load->database();
    }
}

One more changes I have done: While call the model function I was using

//sending to db model
$result = $this->**Users_Model**->customQueryInsertUpdateGetId('**Users**',$data,$isdCode,$mobileNumber);

now I am using

//sending to db model
$result = $this->**users_model**->customQueryInsertUpdateGetId('**users**',$data,$isdCode,$mobileNumber);

and it solved the above issue.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jay Bharat
  • 33
  • 3
0

I'm currently using CodeIgniter 3 on Ubuntu 16.04.
Guys just give the same name everywhere.
My model name was Login_database.

Example:

  1. In the model folder

    class Login_database extends CI_Model
    {
    
    }
    
  2. In the controller when you load the model, do it like this

    $this->load->model('Login_database');
    
  3. In the Autoload file in the config folder, type in

    $autoload['model'] = array('Login_database');
    
gre_gor
  • 6,669
  • 9
  • 47
  • 52