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

前端 未结 16 1204
耶瑟儿~
耶瑟儿~ 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:10

    I use codeigniter 3+. I had the same problem and in my case I changed model file name starting from uppser case.

    Logon_model.php

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

    You can give whatever name you want.

    Styles guides are recommendations and not musts.

    But you have to care to use everywhere the same name.

    For example for Test_Model you have to:

    Class Name

            class Test_Model extends CI_Model
    

    File Name

            Test_Model.php
    

    Load Model

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

    Use Model

            $this->Test_Model
    

    To avoid using hard coding strings you can load model like this:

            $this->load->model(Test_Model::class);
    
    0 讨论(0)
  • 2020-11-30 02:13

    Here is what a model should look like: Make sure yours is like this.

        <?php
        class Logon_model extends CI_Model {
    
        function __construct()
        {
             parent::__construct();
        }
    
        function myFunc()
        {
          // do something
        }
    }
    

    note the upper-case class name.

    To load it use:

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

    note all lower case.

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

    I resolve this with this way:

    1. I rename file do Page_model.php
    2. Class name to Page_model extends...
    3. I call on autoload: $autoload['model'] = array('Page_model'=>'page');

    Works fine.. I hope help.

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

    you must change your model name first letter capital. in localhost small letter work properly but online this not work. for exa:

    common_model.php
    

    replaced it to

    Common_model.php
    
    0 讨论(0)
  • 2020-11-30 02:21

    Just adding my problem i had:

    $this->load->model("planning/plan_model.php");
    

    and the .php shouldnt be there, so it should have been:

    $this->load->model("planning/plan_model");
    

    hope this helps someone

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