当我打开localhost时,我的系统出现问题,显示此错误:
An uncaught Exception was encountered
输入:RuntimeException
消息:无法找到您指定的模型:Project_model
文件名:C:\ xampp \ htdocs \ txu \ system \ core \ Loader.php
行号:344
回溯:
文件:C:\ xampp \ htdocs \ txu \ application \ controllers \ home.php 行:9 功能:型号
文件:C:\ xampp \ htdocs \ txu \ index.php 行:315 功能:require_once
此模型:Project_model.php
class Project_model extends CI_Model{
function __construct()
{
parent::__construct();
}
这是控制器:Project.php
class Project extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->model('project_model');
}
这是我的家庭控制器:home.php
class Home extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->model('Project_model');
}
在此工作之前,我不知道为什么它现在不起作用。并且控制台在localhost中显示错误:
GET http://localhost/txu/ 500 (Internal Server Error)
任何人都可以给我建议或想法吗?谢谢。
答案 0 :(得分:1)
对于项目模块;
将控制器名称创建为Project.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Project extends CI_Controller {
public function index()
{
$this->load->model('project_model');
echo $this->project_model->my_model_func();
echo "<br> This is the Project Controller";
}
}
创建名为Project_Model.php的模型
class Project_model extends CI_Model {
public function my_model_func()
{
echo "Project_model model loaded with my_model_func";;
}
}
查看http://your-base-url/index.php/project上的输出 您应该看到输出为
Project_model model loaded with my_model_func
This is the Project Controller
我希望这对你有用。
答案 1 :(得分:0)
在Codeigniter 2.1版本左右;你实例化如下的模型&gt;请注意,它以大写字母
开头$this->load->model('Project_model');
在codeigniter版本3+上;你总是实例化模型开始小写,或者我应该说小写
$this->load->model('project_model');
因此,如果适合您,我希望您查看您的codeigniter版本。
如果您将模型实例化为&#34; Project_model&#34;,则使用相同,然后将其用作:
$this->Project_model->action();
它具有区分大小写;