Welcome Guest, Not a member yet? Register   Sign In
When to use 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.


Messages In This Thread
When to use parent::Controller(); ? - by El Forum - 01-10-2010, 08:23 AM
When to use parent::Controller(); ? - by El Forum - 01-10-2010, 08:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB