I have core class in application/core/MY_Lang.php, this class extends CI_Lang class, and overrides contructor of base class:
class MY_Lang extends CI_Lang {
function __construct()
{
parent::__construct();
}
}
How i can access to the database object from constructor of my class.
I tried to access CI super object, but class CI_Controller is not loaded for now
if (class_exists('CI_Controller'))
{
$this->CI =& get_instance();
}
Ok, looks like I was wrong about being able to just call get_instance().
But I’ve found a similar post which suggests using a post_controller_constructor “hook” to call your function
See here: CodeIgniter: get_instance inside My_Lang
The documentation for Code Igniter hooks is here: http://ellislab.com/codeigniter/user_guide/general/hooks.html
So I’m guessing that in your application/config/hooks.php file you want to add something like this:
I haven’t tested this, but let me know if you’re not quite getting it to work and I can put together a proper test.
Of course, then in the function you specify in your hook is where you’d want to call get_instance() and then load the database library and do whatever work you want.