Reputation: 415
I was looking around on here for a post that can help me to learn what is needed to globalize variables and instances of CI. I found this great post.
get_instance() in Codeigniter: Why assign it to a variable?
The issue with this is that when I attempted it in my own application I received the following error.
Fatal error: Call to undefined function CI() in .../application/core/MY_Controller.php on line 6
I'm not sure why this is. Can someone elaborate on it?
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
public $module;
public function __construct() {
parent::__construct();
CI()->module = $this->module = $this->router->fetch_module();
}
function CI()
{
static $CI;
isset($CI) || $CI = CI_Controller::get_instance();
return $CI;
}
}
Upvotes: 0
Views: 95
Reputation: 3251
You're defining the function inside your class, so you need to refer to it as an instance method
$this->CI()->module = $this->module = $this->router->fetch_module();
Upvotes: 1