Codeigniter returns "Message: Undefined property: Welcome :: $ load" tries to load the lib auxiliary library

enter image description here

Background Information

I just installed a new copy of CI and modified the hello controller to enable the URL helper so that I can call the base_url method. Then I try to call this method from home.php

Problem: I get the following error message:

 Message: Undefined property: Welcome::$load Filename: controllers/welcome.php 

The code:

Here's what my welcome controller looks like now:

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

The view is as follows:

 <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge"/> <meta charset="utf-8"> <meta name="viewport" content="width = device-width"> <meta name="description" content=""> <!-- Le styles --> <title>test site</title> <script> var BASEPATH = "<?php echo base_url(); ?>"; </script> <link href="<?php echo base_url('assets/css/bootstrap.min.css')?>" rel="stylesheet"> <link href="<?php echo base_url('assets/css/navbar.css')?>" rel="stylesheet"> </head> 

The system dies in the constructor line of the controller where I try to load the library ...

What i have done so far:

But I still get the error. Any suggestions?

Thanks.

Screenshots:

+7
php codeigniter
source share
1 answer

You forgot about an important 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 } } 

parent::__construct . If you do not; The controller will not inherit it from the abstract layer if you override __construct in your own controller.

Until you redefine your __construct , everything is fine. This only happens when you redefine it. You do not have a load function because the hello class is empty (without inheritance), even if it extends CI_Controller (but with an __construct override).

+27
source share

All Articles