php - Codeigniter 加载错误的类
问题描述
我似乎无法加载application/model/Event.php
模型类然后从中访问方法。
相反,CI 加载application/core/App_loader.php并尝试在那里寻找方法。
任何人都可以帮忙解决这个问题吗?
在:application/config/config.php
//$config['subclass_prefix'] = 'MY_';
$config['subclass_prefix'] = 'App_';
事件.php
class Event extends CI_Model {
private $db_main;
function __construct() {
parent::__construct();
$this->db_main = $this->load->database('main', TRUE);
}
function get($arr = array()) {
// ! Trying to access this method ...
}
}
我试图从控制器加载一个名为 Event 的模型类(验证函数 index() 被调用):application/controller/home.php
class Home extends App_Controller {
private $event;
function __construct() {
parent::__construct();
$this->event = $this->load->model('Event');
}
function index() {
$this->method1();
}
function method1() {
$eventArr = $this->event->get(); // << Cant access method
}
Message: Call to undefined method App_Loader::get()
在application/core/App_loader.php 里面:
class App_Loader extends CI_Loader {
function __construct() {
parent::__construct();
}
function aa(){}
function bb(){}
function cc(){}
}
解决方案
参考来自https://www.codeigniter.com/userguide3/general/models.html#loading-a-model
class Event extends CI_Model {
private $db_main;
function __construct() {
parent::__construct();
$this->db_main = $this->load->database('main', TRUE);
}
function get($arr = array()) {
// ! Trying to access this method ...
}
}
class Home extends App_Controller {
function __construct() {
parent::__construct();
$this->load->model('event');
}
function index() {
$this->method1();
}
function method1() {
$eventArr = $this->event->get();
}
}
推荐阅读
- javascript - 如何获取输入类型编号的输入值?
- android - 在虚拟机上使用 android 模拟器时颜色反转
- c# - 在数组上查找空格并在其上插入值 - 麻烦
- c - 在特定 NUMA 节点上创建命名共享内存?
- python - 如何将响应从 request.get 转换为 DataFrame?
- java - 如何有效区分 ANTLR4 规则中的不同标记?
- django - Facebook 注册/在 django rest 中使用自定义手动登录链接
- swift - 通过滑动从 NSTableview 中删除行
- python - 将字符串转换为 int 或 float *如果可能*
- objective-c - Objective C 在 RUNTIME 级别自动释放