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

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

    If you are on Linux then make sure your File name must match with the string passed in the load model methods the first argument.

    $this->load->model('Order_Model','order_model');
    

    You can use the second argument using that you can call methods from your model and it will work on Linux and windows as well

    $result = $this->order_model->get_order_details($orderID);
    
    0 讨论(0)
  • 2020-11-30 02:33

    In CodeIgniter 3.0-dev (get it from github) this is not working because the CI is search as first letter uppercase.

    You can find the code on system/core/Loader.php line 282 or bellow:

    $model = ucfirst(strtolower($model));
    
    foreach ($this->_ci_model_paths as $mod_path)
    {
        if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
        {
            continue;
        }
    
        require_once($mod_path.'models/'.$path.$model.'.php');
    
        $CI->$name = new $model();
        $this->_ci_models[] = $name;
        return $this;
    }
    

    This mean that we need to create the file with the following name on application/models/Logon_mode.php

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

    I experienced the same problem, but I fixed it by altering my application/config/routes.php file.

    I made some restructuring to my controller directories and forget to effect it on the routes file.

    Earlier:

    $route['application/apply'] = 'ex/application/account/create';
    

    and now:

    $route['application/apply'] = 'application/account/create';

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

    Make sure:

    1. First letter uppercase
    2. Class name exact name as file name
    3. Make sure your file ends with .php extension

    In my case I had 1 and 2 correct but forgot to name my file with .php extension. How I forgot, no idea but it sure gave me a hard time trying to figure out the problem

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