Undefined $load property error after upgrading CodeIgniter 1.7 to 2.1

烂漫一生 提交于 2019-12-02 09:22:32

You forgot to call __construct method of CI_Controller class:

public function __construct()
{
    // Call CI_Controller construct method first.
    parent::__construct();

    $this->load->library('language'); // line 25
    $this->language->loadLanguage();
    $this->load_main_lang_file();
    $this->load_visitor_geographical_data();
    $this->load->library('bread_crumb');
}

Note: If you're creating a Controller, it should be placed in application/controllers/, not in application/libraries/.

If the child (inheritor) class has a constructor, the parent constructor won't be called, because you'll override parent's constructor with the child one, unless you explicitly call parent's constructor using parent::__construct();. That's the concept of Polymorphism in object-oriented programming

If you don't call parent::__construct(); when the application controller is initializing, you'll lose Loader and Core class and $this->load would never works.

Using parent::__construct(); is needed only if you want to declare __construct() method in your Controller which it will override the parent's one.

That's true for models as well, but using parent::__construct(); in your model just logs a debug message Model Class Initialized, So if you need to know when Model is initialized (in logs), keep using that, If not, ignore it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!