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

[eluser]123wesweat[/eluser]
Hi,

When writing controllers when do you need
Code:
parent::Controller();

??
#2

[eluser]Cro_Crx[/eluser]
You need to call the parent controllers constructor within your own controllers constructor, eg:


Code:
<?php

class Example extends Controller
{
    function Example()
    {
        parent::Controller();
    }

}


What this does is calls the CI_Controllers constructor before running any of the code in your constructor. This gives you the functionality of the Controller that you need, like the ability to load objects.

Without parent:Controller(); you wouldn't be able to run $this->load->xxxx; or anything else a Controller needs to do Smile

You only need to call that line once. You don't need it in any of the functions except for the contructor.




Theme © iAndrew 2016 - Forum software by © MyBB