我一直看到这个错误 -
这是有问题的功能 -
private function getInfo(){
$this->Features = new UserFeatures_Model($this->ID); //<-- Offending line of Code
/*Other Stuff - Not Relevant*/
}
这是从它被称为 -
的地方public function __construct($UserID = NULL){
parent::__construct( TRUE );
$this->database = $this->load->database('users', TRUE);
$this->table = 'users';
$this->idKey = 'User_ID';
//Assigned UserID should have precedence.
if (!is_null($UserID)) { $this->ID = $UserID; }
//If there exists a UserID within this session, automatically load it.
elseif ($this->session->UserID){ $this->ID = $this->session->UserID; }
if (isset($this->ID)){ $this->getInfo(); }
}
我首先想到的是为什么这样做是因为我在构造函数中调用了getInfo()方法......但我非常确定这不是问题所在。
无论如何,这是它所说的类定义不存在 -
class UserFeatures_Model extends MY_Model {
/*Irrelevant stuff since it's not 'seeing' this class anyway...*/
}
这是目录结构 -
除非我产生幻觉(明显可能,我很累......)
为什么CI / PHP没有找到这个类?
答案 0 :(得分:1)
在调用该模型函数之前,必须在$this->load->model('UserFeatures_Model');
控制器内使用getInfo()
。
private function getInfo($id){
$this->load->model('UserFeatures_Model');
$this->Features = $this->UserFeatures_Model->some_function_inside_model($id);
}