Welcome Guest, Not a member yet? Register   Sign In
parent::Controller()
#1

[eluser]rcahanap[/eluser]
Hello!

Someone suggested CodeIgniter for a project that I am doing, so I am currently going through the video tutorial right now that's on this site titled "Create a Blog in 20 Minutes".

I am getting an error when I have this line:
parent::Controller();

I looked online and someone suggested to replace it with this line and it was OK:
parent::__construct();

I don't know enough about CodeIgniter to know that this is the right way to fix this error.

The version I am using is 2.1.2.

Thanks for your replies.

-Roberto
#2

[eluser]LuckyFella73[/eluser]
Hi,

the tutorial was written when we had Codeigniter version < 2.
Up from CI 2 the CI Controller was renamed from "Controller"
to "CI_Controller". So your controller class has to extend
"CI_Controller" and

Code:
// change this
parent::Controller();

// to:
parent::__construct();

Example from USER GUIDE:
Code:
&lt;?php
class Blog extends CI_Controller {

       public function __construct()
       {
            parent::__construct();
            // Your own constructor code
       }
}
?&gt;
#3

[eluser]PhilTem[/eluser]
If you used
Code:
parent::Controller();

with CI 2.1.2 it will most likely not work since CI 2.x renamed the class Controller to CI_Controller. So you would have to use
Code:
parent::CI_Controller();

The section question is only important if you're running PHP >= 5.3.3 or intend to running PHP >= 5.3.3 since, according to the PHP docu, a function called the same as your class will be treated as
the constructor for PHP < 5.3.3
a separate function for PHP >= 5.3.3

It is recommended to use
Code:
parent::__consruct();
as of PHP >= 5.x to support upward compatibility, however it is not supported in PHP < 5.x i.e. PHP 4 for example.

Therefore it all depends on the system you are or want to be running on.
Some classes solve the problem in the following way:

Code:
class Someclass extends Someotherclass {
  function Someclass {
    $this->__construct();
  }
  
  function __consruct() {
    parent::__construct();
  }
}
#4

[eluser]rcahanap[/eluser]
Ah OK, that explains it then.

Thank you for the post.

Wish me luck this weekend. I'll be creating some pages using Code Igniter!

-Roberto
#5

[eluser]boltsabre[/eluser]
Good luck! It's a great framework once you get used to it!!!




Theme © iAndrew 2016 - Forum software by © MyBB