英文:
Codeigniter does not find model files in models subfolders
问题
在一个子文件夹中保存模型,例如 models/cronjobs/Dbsconnection_model.php 当我使用以下方式加载它时,总是出现“消息:无法找到您指定的模型:Dbsconnection_model”错误:
public function __construct()
{
parent::__construct();
require('application/config/CronJobs/CronjobsConfig.php');
$this->load->model('cronjobs/dbsconnection_model');
[......]
}
如果我将同样的模型移到上一级文件夹中,就没有问题;换句话说,这个函数:
$this->load->model('dbsconnection_model');
如果相关文件也复制到主模型文件夹中,就不会触发任何错误。我还尝试了几种子文件夹名称的组合:
- cronjobs
- Cronjobs
- CronJobs
无论是在文件系统中还是在加载函数中都进行了更改。有什么建议吗?
英文:
Saving a model in a sub-folder such as models/cronjobs/Dbsconnection_model.php I always get a "Message: Unable to locate the model you have specified: Dbsconnection_model" error when i load it with
public function __construct()
{
parent::__construct();
require('application/config/CronJobs/CronjobsConfig.php');
**$this->load->model('cronjobs/dbsconnection_model');**
[......]
If i take the same model in the upper folder there are no troubles; in other words, this function
$this->load->model('dbsconnection_model');
does not trigger any error if the relative file is copied in the main models folder too. I tried also several combinations for the subfolder name:
- cronjobs
- Cronjobs
- CronJobs
changing it both in the filesystem and in the loading function. Any ideas?
答案1
得分: 0
你需要将模型类的第一个字母大写,然后它就可以正常工作。
这样你仍然可以这样调用它:
$this->load->model('cronjobs/dbsconnection_model');
但是模型文件本身需要以大写字母开头。
例如:
application/models/cronjobs/Dbsconnection_model.php
英文:
You need to capitalize the first letter of your model class and it will work.
So you can still call it like
$this->load->model('cronjobs/dbsconnection_model');
But the model file itself needs to start with a capital letter.
For example
application/models/cronjobs/Dbsconnection_model.php
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论