Welcome Guest, Not a member yet? Register   Sign In
Send errors via email
#3

Not tried in CI2 but others had used it and it worked for them in CI2 but I cant find any code for CI3. I have now tried various examples but none worked so far, the latest code below looks to be o.k. but is giving an error 'Notice: Trying to get property of non-object' when trying to load the config but I cant figure out why.

PHP Code:
class MY_Exceptions extends CI_Exceptions {
    
    protected 
$CI;
    
    public function 
__construct()
    {
            
// Assign the CodeIgniter super-object
            
$this->CI =& get_instance();
    }

    public function 
log_exception($severity$message$filepath$line)
    {

        
// this allows different params for different environments
        
$this->CI->config->load('email_php_errors');

        
// if it's enabled
        
if (config_item('email_php_errors'))
        {
            
// set up email with config values
             
$this->CI->load->library('email');
             
$this->CI->email->from(config_item('php_error_from'));
             
$this->CI->email->to(config_item('php_error_to'));

            
// set up subject
            
$subject config_item('php_error_subject');
            
$subject $this->_replace_short_tags($subject$severity$message$filepath$line);
             
$this->CI->email->subject($subject);

            
// set up content
            
$content config_item('php_error_content');
            
$content $this->_replace_short_tags($content$severity$message$filepath$line);

            
// set message and send
             
$this->CI->email->message($content);
             
$this->CI->email->send();
        }

        
// do the rest of the codeigniter stuff
        
parent::log_exception($severity$message$filepath$line);
    }

    private function 
_replace_short_tags($content$severity$message$filepath$line)
    {
        
$content str_replace('{{severity}}'$severity$content);
        
$content str_replace('{{message}}'$message$content);
        
$content str_replace('{{filepath}}'$filepath$content);
        
$content str_replace('{{line}}'$line$content);

        return 
$content;
    }


Reply


Messages In This Thread
Send errors via email - by Rushty - 02-17-2015, 10:14 AM
RE: Send errors via email - by gadelat - 02-18-2015, 02:13 AM
RE: Send errors via email - by Rushty - 02-18-2015, 10:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB