开发者

Why won't the Model load the database?

开发者 https://www.devze.com 2023-03-28 23:36 出处:网络
I have a Model called blog_model.The code for its constructor is below: class blog_model extends CI_Model {

I have a Model called blog_model. The code for its constructor is below:

class blog_model extends CI_Model {
function __construct() {
    parent::__construct();
    $this->load->database();
}

I keep getting an error whenever the code runs $this->load->database();. The error t开发者_运维百科hat I get is this:

Fatal error: Call to a member function database() on a non-object in C:\wamp\www\Project\application\models\blog_model.php on line 7

This might be a helpful clue, whenever I hover my mouse pointer over the this->load->database(); part, this shows up:

CI_Loader.database($params, $return, $active_record)

How do I fix this error?


load isn't defined yet in that context. My normal workaround is:

$CI =& get_instance();
$CI->load->database();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号