[eluser]Unknown[/eluser]
Hi everyone
I'm having a weird problem with CI. I'm trying to extend the Email class and, at the same time, configure some of the Email class parameters in a email.php config file. Here's the basic code:
Code:
class GS_Email extends CI_Email {
public function __construct () {
parent::__construct();
$this->from(
$CI->config->item('gs_email_from_email'),
$CI->config->item('gs_email_from_name')
);
}
function send_activation_email ($activation_link) {
$CI =& get_instance();
$this->subject($CI->config->item('gs_user_activation_email_subject'));
$body = str_replace(
'[[[ACTIVATION_LINK]]]',
$activation_link,
$CI->config->item('gs_user_activation_email_body')
);
$this->message($body);
return $this->send();
}
}
The problem with it is that the config file is not automatically loaded when I use the class. The only way I found to get it to work is to include 'email' in the autoload (which should not be necessary, right?) and initialize the Email class this way:
Code:
public function __construct () {
parent::__construct();
$CI =& get_instance();
$this->initialize($CI->config->config);
$this->from(
$CI->config->item('gs_email_from_email'),
$CI->config->item('gs_email_from_name')
);
}
Is this a bug? Also, is there a way to avoid using
$CI =& get_instance(); inside every single function?
Thank you so much!