EllisLab text mark
Advanced Search
     
CI 2.0, HMVC, get_instance() confusion
Posted: 28 January 2011 07:11 AM   [ Ignore ]
Joined: 2010-07-01
23 posts

When I install CI 2.0 and Modular Extensions, then extend MX_Controller with MY_Controller, my Menu library stops working.  As far as I can see it’s because the get_instance() method returns a CI Object, not a controller_name Object, when I run it in a controller.  Does this make sense?

As a result, I can no longer access controller member variables using $CI =& get_instance(), followed by $CI->var_name.

Related question: I want to use HMVC throughout the project, so I was planning for all controllers to extend MY_Controller (which in turn is based on MX_Controller).  I was planning to do this irrespective of whether hte controller is in a module, or in the native CodeIgniter controller directory.  Is this fine?

Thanks!

 
Posted: 10 December 2011 01:53 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2009-03-30
1301 posts

You don’t need to extend MX_Controller unless you are planning on running a controller within another controller. In alot of cases the code be put into a library. Otherwise, your controller should just extend MY_Controller.