问题描述
我一直在尝试为我正在建设的网站加载一些模型。但是,由于未知的原因,它会带来以下错误:
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 ?
如何解决这个问题?
EDIT:模型文件的标题:
EDIT : Header for the model file :
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();
}
...
现在,如果您的应用程序模型可访问,则是尝试在浏览器中打开它 - 如下所示:
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模型访问“无法找到您指定的模型”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!