CodeIgniter HMVC extends MX_Controller, unable to use get_instance properly
In application/third_party/MX/Controller.phpat the end of the constructor (after line 54)i added
/* allow CI_Controller to reference MX_Controller */CI::$APP->controller = $this;
if you look at the code $this refers to the current class which is MX_Controller and CI::$APP refers to the CI_controller (look at the MX/Base.php file)
so now its simple...to get the reference to CI_Controllerwe will do (as per normal)
$this->CI =& get_instance();
and to get reference to MX_Controller we will do
$this->CI =& get_instance()->controller;
I had the same problem, found that post and it made my website work, give it a try maybe?
"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."
for me you don't need to get the instance so my try would be this:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); echo $this->show_something();?>
instead of
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); $ci =& get_instance(); echo $ci->show_something();?>
anyway it is good practice to set own libraries and do somenthing like:
$this->load->library('foo_lib');$this->foo_lib->show_somenthing();