I have been trying to load some models for this website I am building. However, for an unknown reason, it will bring the following error :
An Error Was Encou
Changing the name of model name starting with Uppercase works. Example : Login_model.php instead of login_model.php
Adding to @jakentus answer, below is what worked for me:
Change the file name in the models package to Logon_model.php
(First letter upper case as @jakentus correctly said)
Change the class name as same as file name i.e.
class Logon_model extends CI_Model
Change the name in the load method too as
$this->load->model('Logon_model');
Hope this helps. Happy coding. :)
Change your model file name, start with upper case letter like this: Logon_model.php
This happens when we migrate our project from windows server to LINUX server because linux is case sensitive while windows is not.
So, on windows even if don't write file name with upper case then also it will work fine but not on linux.
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.
Models must be named and called with the first letter of the model name capitalized and the rest in lowercase.
For example: $this->load->model('Logon_model');
and:
class Logon_model extends CI_Model {
...
But you are correct about the file name.
First letter of file name and class name must be in Uppercase.
Your model class will be
class Logon_model extends CI_Model
and the file name will be Logon_model.php
Access it from your contoller like
$this->load->model('Logon_model');