Welcome Guest, Not a member yet? Register   Sign In
using config data in custom library
#1

[eluser]Mahmoud M. Abdel-Fattah[/eluser]
Here's my Custom Library code
Code:
class Emails {
    
    public $CI;
    
    function Emails () {
        // Loading CodeIgniter Base Class
        $CI =& get_instance();
        $CI->load->library('email');
    }
    
    /**
    * User Validation E-mail
    * @method validation
    */
    function validation_mail($user_name, $user_email, $activation_code) {
        $message = "Dear" .  $user_name . ", Thank you for registering at the " . $CI->config->item('site_name');

        $CI->email->from('no-reply@' . $CI->config->item('domain_name'), $CI->config->item('site_name'));
        $CI->email->to($user_email);
        $CI->email->subject($CI->lang->line('email_account_activation'));
        $CI->email->message($message);
        $CI->email->send();
    }
}

and I'm getting this error :
Fatal error: Call to a member function item() on a non-object in Emails.php on line 16
#2

[eluser]TheFuzzy0ne[/eluser]
The $CI variable doesn't exist in your global scope. In your constructor, changing:

Code:
$CI =& get_instance();

to

Code:
$this->CI =& get_instance();

will resolve your problem.
#3

[eluser]Mahmoud M. Abdel-Fattah[/eluser]
Thanks TheFuzzy0ne, it works fine after I'd replaced ALL
Code:
$CI->
with
Code:
$this->CI->

isn't any way to make it $CI-> ??
#4

[eluser]TheFuzzy0ne[/eluser]
Whoops. Well spotted.




Theme © iAndrew 2016 - Forum software by © MyBB