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

前端 未结 16 1205
耶瑟儿~
耶瑟儿~ 2020-11-30 02:10

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         


        
相关标签:
16条回答
  • 2020-11-30 02:24

    Changing the name of model name starting with Uppercase works. Example : Login_model.php instead of login_model.php

    0 讨论(0)
  • 2020-11-30 02:26

    Adding to @jakentus answer, below is what worked for me:

    1. Change the file name in the models package to Logon_model.php (First letter upper case as @jakentus correctly said)

    2. Change the class name as same as file name i.e.

      class Logon_model extends CI_Model

    3. Change the name in the load method too as

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

    Hope this helps. Happy coding. :)

    0 讨论(0)
  • 2020-11-30 02:29

    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.

    0 讨论(0)
  • 2020-11-30 02:30

    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.

    0 讨论(0)
  • 2020-11-30 02:30

    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.

    0 讨论(0)
  • 2020-11-30 02:31

    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');

    0 讨论(0)
提交回复
热议问题