0

I have implemented Codeigniter HMVC which works fine. Then I'm extending MX_Controller with MY_Controller to share functionality and properties between all my modules and to keep my code DRY.

But I noticed that while extending MY_Controller from MX_Controller I can no longer access the public properties from MY_Controller on any of the extended child classes.

Some sample code:

class MY_Controller extends MX_Controller {

    public $variable;

    function __contruct()
    {
        parent::__contruct();
        $this->variable = 'Foo';
    }
}

Then on any controller which I extend from MY_Controller:

class Foo extends MY_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function someFunction()
    {
       var_dump($this->variable);
    }

}

When I trying to access the public property $variable in any child controller I get Null or empty string.

I have searched high and low for this with no luck, my only guess is an issue with HMVC MX_Controller. Any Ideas?

Hashem Qolami
  • 97,268
  • 26
  • 150
  • 164
Cabreran
  • 1
  • 2
  • Is there a spelling mistake in the first constructor? `__contruct()` – Yan Berk Jan 23 '14 at 23:30
  • Yes Yan Berk, that was it. I noticed the issue that same day after getting a PHP error about it. I fixed it. What I never understood was, how can this be going on for days without yanking a php error like it did at the end. – Cabreran Jan 27 '14 at 20:57

1 Answers1

0

After hours of checking, it was a simple mistake on my behalf. I had misspelled the name parent::__contruct on MY_Controller, it should be parent:__construct.

Cabreran
  • 1
  • 2