Welcome Guest, Not a member yet? Register   Sign In
Get an email anytime there's a CI Error - MY_Exceptions library
#1

[eluser]SitesByJoe[/eluser]
I wrote a whole bunch of cool libraries for the sites I've been working on recently so I thought I'd share at least one with you.

The helper overrides Codeigniter's normal exceptions behaviours and adds in a nicely formatted email message sent for each error. All you need to do is add your own email in and you'll be alerted anytime you have any type of error!

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed.');

class MY_Exceptions extends CI_Exceptions {

    function My_Exceptions()
    {
        parent::CI_Exceptions();
    }

    function log_exception($severity, $message, $filepath, $line)
    {  
        $CI =& get_instance();
            
        $severity = ( ! isset($CI->levels[$severity])) ? $severity : $CI->levels[$severity];

        log_message('error', 'Severity: '.$severity.'  --> '.$message. ' '.$filepath.' '.$line, TRUE);

        $CI->load->library('email');
        $CI->email->from('[email protected]', 'Your Name');
        $CI->email->to('[email protected]');
        $CI->email->subject('CodeIgniter Error Alert');
        $CI->email->message('URL: ' . current_url() . ' Severity: '. $severity. '  --> '. $message . ' File: ' . $filepath . ' Line: ' . $line);
        $CI->email->send();
    }

}

/* End of File: MY_Exceptions.php */
/* Location: ./system/application/libraries/MY_Exceptions.php */




Theme © iAndrew 2016 - Forum software by © MyBB