1

I'm building a simple web application using CodeIgniter 3.0.3, and have run into a lot of issues regarding capitalization consistency. The CI 3.x documentation clearly states that Model files should be ucfirst and referenced using lcfirst i.e. file application/models/Foobar_model.php, loaded using $this->load->model('foobar_model'), and called with $this->foobar_model. Source: Official CI 3.x User Guide.

When I follow those rules, I get the following error message Unable to locate the model you have specified: foobar_model. Referencing the model using Ucfirst i.e. $this->load->model('Foobar_model') and $this->Foobar_model generates the exact same error message. I am able to resolve the issue by making my filename lcfirst application/models/foobar_model.php while the class name inside the file remains Ucfirst. As long as I name my file lcfirst foobar_model.php, it does not seem to matter whether I use Ucfirst or lcfirst to reference it from inside my controllers.

Strangely, I have found that I need to use application/controllers/Ucfirst_controller.php for my controllers with case-sensitive routing i.e. $route['default_controller'] = 'Ucfirst_controller';. I receive a 404 error when trying to route $route['default_controller'] = 'lcfirst_controller'; to application/controllers/lcfirst_controller.php.

Everything I have found on stackoverflow and other forums for CodeIgniter model and controller issues seems to involve people using lcfirst instead of Ucfirst on CodeIgniter 3.x, or using Ucfirst instead of lcfirst on CodeIgniter 2.x.

Basically my question is where is this case inconsistency coming from and how can I fix it? I want to follow standards so that others can join my project at a later point.

Other Info: I don't think that this should matter, but just in case. I am developing on LAMP on an Ubuntu machine with ext4 file formatting which is obviously case sensitive. I plan to deploy my project with Google Compute Engine running debian-7-wheezy with a HHVM stack. I am currently developing with just one partner, who is developing on a MAMP stack with non case-sensitive file formatting so he does not experience any of these issues.

Thanks everyone :~)

snoopy
  • 11
  • 2
  • If possible, match your dev environment to your production environment unless you are looking forward to hunting down bugs on a production system. – MonkeyZeus Nov 03 '15 at 21:33
  • I don't have the time to sift through the CodeIgniter codebase right now but I highly recommend checking out precisely what happens when you call `$this->load->model();` by looking at `/system/core/Loader.php` and find `function model(){}` and keep in mind [this](http://stackoverflow.com/a/5260230/2191572) and [this](http://stackoverflow.com/a/5643544/2191572) – MonkeyZeus Nov 03 '15 at 21:52
  • Thanks for the advice @MonkeyZeus , it seems that somehow my dev partner was using the old loader.php from CI 2.x so it was set to expect models as lcfirst, and while merging code at some point that inadvertently downgraded my loader.php. Will post as answer once I confirm that this fixes my issues. Thanks again – snoopy Nov 03 '15 at 22:28
  • Oh, well that was unexpected lol. Let me know how it goes! – MonkeyZeus Nov 03 '15 at 22:34
  • fwiw - i have used UC first for calling models in CI 3 and it worked fine in local mamp and standard cpanel type php hosting. (i was doing it for testing autocomplete with phpstorm). anyway this sounds like something very specific to your environment, but you could try posting to codeigniter forums http://forum.codeigniter.com – cartalot Nov 03 '15 at 22:48
  • Yeah my issue was resolved by making sure ALL of my CI `/system/core/*.php` files were updated to 3.x CI code. Thanks again for pointing me in the right direction @MonkeyZeus. Still not completely sure how my Loader.php was not updated correctly, I'm guessing due to not overwriting it properly. Everything else seemed to be updated. Issue solved. – snoopy Nov 04 '15 at 01:00
  • It's super simple to maintain two versions of CodeIgniter if that is something you require. Just make sure to properly define the path in your `public_html/index.php` file – MonkeyZeus Nov 04 '15 at 02:58

1 Answers1

0

My system/core/Loader.php file was not updated properly when I updated from CI 2.x to 3.0.3. Properly updating this file resolved my case inconsistency issues, I am now able to name my models and controllers Ucfirst.php and reference them as $this->lcfirst and everything works properly.

snoopy
  • 11
  • 2