Unable to locate the model you have specified - CodeIgniter Issue

匿名 (未验证) 提交于 2019-12-03 02:31:01

问题:

I'm getting an unable to locate model error.

$this->load->model('1/Gift_model'); 

My model file name is gift_model.php within /models/1/.

I declare the model the following way.

class Gift_model extends CI_Model { 

According to CodeIgniter's documentation I'm doing it the correct way. Any suggestions? I have 5 other models named exactly the same way and they're all loading fine.

回答1:

  1. Make the model class name Uppercase My_model
  2. Make the model php file name Lowercase my_model
  3. Load the model using Lowercase (file name) $this->load->model('my_model');


回答2:

$this->load->model('1/Gift_model'); should be $this->load->model('1/gift_model');. Lowercase on this load argument and the php filename, uppercase on the class name within the file (you had two of three correct).



回答3:

http://www.codeigniter.com/userguide3/installation/upgrade_300.html

Starting with CodeIgniter 3.0, all class filenames (libraries, drivers, controllers and models) must be named in a Ucfirst-like manner or in other words - they must start with a capital letter.

Used to be the model files started with lower case, but they changed it.



回答4:

Ensure that the the model name is Gift_model and the class name is also Gift_model

class Gift_model extends CI_Model {  } 

but loading the class is '1/gift_model' NOT 'Gift_model'

$this->load->model('1/gift_model'); 

hope this was helpful



回答5:

The problem is that your file name is all lowercase (gift_model.php) while you are loading Gift_model within CodeIgniter. Either change the file name to Gift_model.php or update your code accordingly.



回答6:

Are you calling the parent's constructor for the model?

class Gift_model extends CI_Model {     function __construct()     {         parent::__construct();     } 


回答7:

-> Model Class name must be Uppercase -> Model PHP file name must be Lowercase -> Load Model using Lowercase(filename): $this->load->model('gift_model', TRUE); 


回答8:

`if using codeignitor 3.1.3
every thing same otherwise showing error class name => My_model

file name => My_model.php

load model => $this->load->model('My_model');

call function => $this->My_model->function();`



回答9:

Starting with CodeIgniter 3.0, all class filenames (libraries, drivers, controllers and models) must be named in a Ucfirst-like manner or in other words - they must start with a capital letter.

(Source: CI docs)



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!