我似乎无法加载application/model/Event.php
模型类,然后从中访问方法。
相反,CI会加载 application / core / App_loader.php 并尝试在那里查找方法。
任何人都可以帮忙解决此问题吗?
在: application / config / config.php
//$config['subclass_prefix'] = 'MY_';
$config['subclass_prefix'] = 'App_';
Event.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(){}
}
答案 0 :(得分:1)
引用自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();
}
}