<?php class TestController extends CI_Controller{ function __construct(){
parent::__construct(); } function index(){ echo'ok'; } function callModel(){ $this->load->model('Testmode'); $this->Testmode->result(); }
}
复制代码
4.创建testmode.php
PHP复制代码
<?php class Testmode extends CI_Model{ function __construct(){
parent::__construct(); } function result(){ print_r($this->db); }
错误提示: A PHP Error was encounteredSeverity: Notice
Message: Undefined property: TestController:db
Filename: core/Model.php
Line Number: 50
解决方法:
修改以上第4步:
PHP复制代码
<?php class Testmode extends CI_Model{ function __construct(){
parent::__construct(); } function result(){ [color=Red]$this->load->database();//手动加载数据库 print_r($this->db); }