I got error Fatal error: Class ‘CI_Controller’ not found in ….\core\CodeIgniter.php on line 233
I create a class called My_Exceptions in application/core/My_Exception.php
Basically, I want to get email when user gets error from my site.
<?php
class My_Exceptions extends CI_Exceptions{
var $CI="";
function __construct(){
parent::__construct();
$this->CI =& get_instance();
}
function show_404($page = '', $log_error = TRUE)
{
$heading = "404 Page My Not Found";
$message = "The page you requested was not found.";
// By default we log this, but allow a dev to skip it
if ($log_error)
{
log_message('error', '404 Page Not Found --> '.$page);
}
//Email to Developer
$this->CI->load->library('email');
$uri = $this->CI->uri->uri_string();
$this->CI->email->from('error-donotreply@YOURAPP.com', 'APP Error');
$this->CI->email->to('youremail@example.org');
$this->CI->email->subject('APP Error [severity: '.$severity.']');
$this->CI->email->message("Page not Found. From URL: ".$uri);
$this->CI->email->send();
echo $this->show_error($heading, $message, 'error_404', 404);
exit;
}
}
Please help !!!
The Exceptions class is loaded BEFORE the main CI_Controller.
This means when an error occurs – you cannot use CI to send an email, because “$this->CI” does not exist.
Your options are to either use the native PHP to send the email, or what I do; automatically email yourself the error logs from the day before (using a CRON job). That way you can review all the errors once a day.