CodeIgniter PHP Model Access quot;Unable to locate the model you have specifiedquot;(CodeIgniter PHP 模型访问“无法定位您指定的模型)
问题描述
我一直在尝试为我正在构建的网站加载一些模型.但是不知什么原因,会带来如下错误:
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 Encountered
Unable to locate the model you have specified: logon_model
现在,我已经完成了我的研究.问题在于 IC 以小写形式处理文件名.但是,我的文件和文件调用都是小写的,如下所示:
Now , I have done my research. The problem would be that IC processes file names in lowercase. However, both my file and the file calling is in lower case, as shown here :
echo "VALIDATING";
// Validation passed. Off we go to account info verification from AA's database. God help us all.
$this->load->model('logon_model');
echo "FOUND MODEL";
$res = $this->logon_model->verify_user($this->input->post('username'),$this->input->post('password'));
echo $this->input->post('username');
echo $this->input->post('password');
执行未到达FOUND MODEL",因此停止模型加载.我曾尝试使用:
The execution does not reach "FOUND MODEL", thus stops on the model loading. I have tried to use:
$this->load->model(site_url('logon_model'));
没有结果.需要说明模型文件是否正确放置在正确的模型文件夹中?
With no results. Need to mention the model file is correctly placed in the right model folder ?
我该如何解决这个问题?
How can I fix this ?
模型文件的标题:
class Logon_model extends CI_Model {
....
推荐答案
创建模型时,需要将文件放在application/models/
中,文件名全部小写 - 如logon_model.php
When creating models, you need to place the file in application/models/
and name the file in all lowercase - like logon_model.php
logon_model.php
应包含以下内容:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Logon_model extends CI_Model
{
public function __construct()
{
parent::__construct();
}
...
现在,您可以做的是测试您的应用程序模型是否可访问,就是尝试在浏览器中打开它 - 如下所示:
http://example.org/application/models/logon_model.php
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
如果您看到文本不允许直接访问脚本,则表示您找到了正确的文件(如果您有疑问,请尝试在第一行的 exit() 中写入其他内容).
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.
这篇关于CodeIgniter PHP 模型访问“无法定位您指定的模型"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CodeIgniter PHP 模型访问“无法定位您指定的模型"
基础教程推荐
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01