Can't access public properties from MY_controller when extending from MX_Controller in HMVC

StackOverflow https://stackoverflow.com/questions/21319388

  •  01-10-2022
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top