<?php
class Blog extends CI_Controller {
function Blog() {
parent::CI_Controller();
}
}
I'm trying to create a constructor in Code Igniter for my class 'Blog' and the above code is giving me a fatal error:
Fatal error: Call to undefined method CI_Controller::CI_Controller() in C:\xampp\htdocs\mysites\blog\application\controllers\blog.php on line 5
How do I fix this?
(I'm going through a online video tutorial on the official code igniter website but I think the tutorial is about 2 years out of date as some of the things are not working when I follow them exactly as shown in the video, this being one of them - the link to the video is here - I encounter this problem towards the end of the tutorial about 8 minutes in)
If you find that you need a particular model globally throughout your application, you can tell CodeIgniter to auto-load it during system initialization. This is done by opening the application/config/autoload. php file and adding the model to the autoload array.
Constructor is a function that is automatically called when instantiated. this function helps us to intialize the things that we are going to need frequently in our code like when we have to load the models of helpers like form e.t.c.
It should be this...
<?php
class Blog extends CI_Controller {
function __construct() {
parent::__construct();
}
}
The tutorial you are probably going through is based on 1.7.2 which had a core of php4 which did not use the php5 __construct()
method of building Class constructors. Codeigniter 2.0.0 has a php5 core and uses it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With