CodeIgniter Forums
How to pass HMVC main controller global variables to modules - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to pass HMVC main controller global variables to modules (/showthread.php?tid=48734)



How to pass HMVC main controller global variables to modules - El Forum - 01-26-2012

[eluser]valchazzz[/eluser]
My problem - in HMVC module i can't access defined in main controller "global" variables.

It's not horrible to pass whole ci $this object from main controller to module constructor?

main controller, part of _remap:
Code:
$this->variable = 'test';
// here we pass main ci object to module
$module_html = $this->load->module('welcome', $this);
$module_html->index();

and here is welcome constructor, here i will work with $my variable, to access global variables:
Code:
public $my;
  // here we get $this from main controller
  function  __construct(& $my)  {
    parent::__construct();
    $this->my = $my;
  }

  function index () {
    // here we work with variables from main controller
    echo $my->variable;
    $my->variable = 'test2';
    ...
  }

I see it works, but maybe i just broke HMVC idea...


How to pass HMVC main controller global variables to modules - El Forum - 01-28-2012

[eluser]valchazzz[/eluser]
Few days and no answer...