Welcome Guest, Not a member yet? Register   Sign In
loading my model to load_class
#5

I see ... Well, CI certainly doesn't make this easy and you will indeed have to use load_class() to be 100% safe, but only for the email library.

You've made 2 design decisions that are inherently bad for this:

1. Getting the recipients from a model. It's fine if you don't want to hard-code them, but they belong in a configuration file.
2. Emailing about every single show_error() call. What you need is notifications for actual application logic errors, not ones caused by the client (CSRF and 404 errors are client ones). A single bot trying to access random URIs on your app will quickly flood your email recipients; this is a very bad idea.

And then there's another detail that you haven't thought about - all of the important show_*() calls are only triggered if you have display_errors enabled, which must never be the case in production. So, you should rather hook into the actual error and exception handlers (where it is decided whether an error should be logged, displayed, both or neither).

Having eliminated CSRF and 404 errors from the set, recipients being in standard config, and knowing that extending/overriding CI_Exceptions won't work, you can use a pre_controller hook to do something like this:

Code:
function send_error_email($error_contents)
{
    // get recipients via get_config()
    // load CI_Email via load_class('Email', 'library')
    // send the $error_contents
}


function _custom_error_handler($severity, $message, $filepath, $line)
{
    send_error_email(func_get_args());
    _error_handler($severity, $message, $filepath, $line); // this forwards the call to CI's error handler
}

function _custom_exception_handler($exception)
{
    send_error_email($exception);
    _exception_handler($exception); // again, forward back to CI's handler
}

set_error_handler('_custom_error_handler');
set_exception_handler('_custom_exception_handler');
Reply


Messages In This Thread
loading my model to load_class - by Vitaly83 - 10-31-2017, 06:57 AM
RE: loading my model to load_class - by Narf - 10-31-2017, 09:18 AM
RE: loading my model to load_class - by Vitaly83 - 10-31-2017, 10:31 PM
RE: loading my model to load_class - by Narf - 11-01-2017, 05:05 AM
RE: loading my model to load_class - by Vitaly83 - 11-01-2017, 05:51 AM
RE: loading my model to load_class - by Vitaly83 - 11-02-2017, 02:30 AM
RE: loading my model to load_class - by Narf - 11-02-2017, 03:38 AM
RE: loading my model to load_class - by Vitaly83 - 11-02-2017, 04:12 AM
RE: loading my model to load_class - by Narf - 11-02-2017, 06:15 AM
RE: loading my model to load_class - by Vitaly83 - 11-02-2017, 07:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB