codeigniter returns “Message: Undefined property: Welcome::$load” trying to load helper lib

前端 未结 1 1891
闹比i
闹比i 2021-01-11 14:05

Background Information

I just installed a fresh copy of CI and modified the welcome controller to include the url Helper so I can call the

相关标签:
1条回答
  • 2021-01-11 14:33

    You forgot a crucial thing;

    class Welcome extends CI_Controller {
        public function __construct()
        {
            parent::__construct();
            $this->load->helper('url'); //Loading url helper    
        }   
    
        public function index()
        {
            $this->load->view('home'); //Loading home view
        }
    }
    

    The parent::__construct. If you don't do that; the Controller will not inherit it's abstract layer when you override the __construct in your own controller.

    As long as you don't override your __construct it's all ok. It only happens when you override it. You don't have the load functionality because the Welcome class is empty (no inheritance), even if it extends the CI_Controller (but with a __construct override).

    0 讨论(0)
提交回复
热议问题