Welcome Guest, Not a member yet? Register   Sign In
Customizing error templates and sending an e-mail when an it ocurr
#1

[eluser]FernandoMM[/eluser]
Hello,

How can i customize the html of the error that code igniter shows?

whenever an error happens my site's layout get broken, so i would like to change it.


Also, is it possible to send an e-mail when an error happen with some detailed information like hour, type of error, request data etc.

Thanks!
#2

[eluser]Sam Dark[/eluser]
Look at your application/errors directory. There are some error_* files to customize.
#3

[eluser]FernandoMM[/eluser]
But when i upgrade code igniter, all my changes will be overwriten, right?

Isn't there a way to do this like hooks do for functions?


Thanks for the answer.
#4

[eluser]Mirage[/eluser]
Quote:But when i upgrade code igniter, all my changes will be overwriten, right?

That potential is always there and true for any core extensions, etc. you might apply for a given site. The errors directory is rarely updated so you can just exclude that from your updates, unless the upgrade doc instructs you to otherwise. Easy enough, though I'll admit that it'd make more sense for the distribution to have the error message templates in the system directory, overridden by those placed in the application directory.

Quote:Isn’t there a way to do this like hooks do for functions?

Depends on what you're trying to catch. The system provided classes will call show_error, show_404, etc pretty liberally. These global, public functions in turn call their counterparts in the Exceptions library. You could override the functionality in that library with a core extension. In the extension, simply override the error functions, calling your own sub-handlers (to send email, etc.) and then execute the parent function for business as usual:

MY_Exceptions.php
Code:
class MY_Exceptions extends CI_Exceptions {

    function show_error($msg) {
        // send email notification code and other stuff here
        // perhaps with a hook?
        global $EXT;
        $EXT->_call_hook('my_special_error_hook');
        
        // continue as usual
        parent::show_error($msg);
    }
}

HTH,
-m
#5

[eluser]Yash[/eluser]
Still I don't like the way CI deals page errors
#6

[eluser]Mirage[/eluser]
Quote:Still I don’t like the way CI deals page errors

I hope you file feature requests. Having some hooks for error handling, and/or reserved page_not_found routes sounds like a reasonable thing to have, IMHO.

Cheers,
-m




Theme © iAndrew 2016 - Forum software by © MyBB