我在加载模型时遇到问题,我有这样的代码
function __construct() {
$this->load->model("admin_model");
parent::__construct();
}
function login() {
$log = $this->admin_model->login($username, $pass);
}
如果我使用上面的代码,我会收到此错误 遇到PHP错误
Severity: Notice
Message: Undefined property: admin_controller::$admin_model
Filename: controllers/admin_controller.php
Line Number: 43
Fatal error: Call to a member function admin_login() on a non-object in C:\xampp\htdocs\ci\application\controllers\admin_controller.php on line 43
答案 0 :(得分:1)
将此代码放在function parent::__construct();