martintrapp
martintrapp

Reputation: 819

Codeigniter: Extend CI_Lang class when controller loaded to use &get_instance()

I want to extend my CI_Lang class to get language values from the database. So I created a copy of the CI_Lang file and rewrote the load and construct functions.

private $CI;
function __construct()
{
    parent::__construct();             
    log_message('debug', "Language Class Initialized");              
    $this->CI = &get_instance();
}

I enabled hooks in the config file and created a new hook:

$hook['post_controller_constructor'] = array(
                            'class'    => 'MY_Lang',
                            'function' => '__construct',
                            'filename' => 'MY_Lang.php',
                            'filepath' => 'hooks'
                            );

This is working correctly. However, when I try to load languages, it's still using the old functions from CI_Lang and not the extended one. Any ideas?

Upvotes: 0

Views: 1201

Answers (1)

martintrapp
martintrapp

Reputation: 819

Ok I found the solution without using any hooks.

First: I had to place MY_Lang.php to 'core' folder.

Second: "$this->CI = &get_instance();" has to be placed in the "load" function and not in the construct.

Hope it helps, its working here. :)

Upvotes: 1

Related Questions