开发者

get_instance() is returning null in Codeigniter 2

开发者 https://www.devze.com 2023-03-29 15:31 出处:网络
I need to load my models without $this->load->model. I have to load it like this: $modelName = new ModelName();//from a controller

I need to load my models without $this->load->model. I have to load it like this:

$modelName = new ModelName();//from a controller

class ModelName{
  public function __construct(){
        $CI =&ge开发者_运维问答t_instance();
        var_dump($CI);//null
  }
}

It is working fine, but the $CI =&get_instance(); is actually null. Any idea why?

Edit 1

If I am trying the get_instance from a regular Controler, it is working (also from the helper).

I am loading the model with require_once


Try extending CI_Model.

class ModelName extends CI_Model {
    public function __construct(){
        $CI =&get_instance();
        var_dump($CI);
    }
}
0

精彩评论

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

关注公众号