Accessing controller public controllor properties from a hmvc module

478 Views Asked by At

Am working with wiredesignz modular extensions for codeigniter, and i was wondering if its possible to access a regular codeigniter controller's public property from a module's controller for example, this is a regular ci controller

<?php

class Dog extends CI_Controller {
    public $name;


    function __construct()
    {
       $this->name = "xyz";
     }

}

and this a module controller

<?php
  class Test extends MX_Controller {
     function get_name()
     {
         //access the $name property of the dog controller here
     }
  }
1

There are 1 best solutions below

0
On BEST ANSWER

If you're using HMVC there's no reason why all or any of your controllers can't inherit from MX_Controller. You can have controllers in your normal application/controllers or application/core folders that inherit MX_Controller, they don't have to be "module" controllers. If you need to access properties from one controller in another why not create a base controller e.g. MY_Controller that extends MX_Controller, put it in either application/controllers or application/core and then every time you create a "module" controller simply inherit from MY_Controller instead of MX_Controller.

Don't forget you can load any module controller and use it like a library class.