Error Handling¶
Codingox lets you build error reporting into your applications using the functions described below. In addition, it has an error logging class that permits error and debugging messages to be saved as text files.
Note
By default, Codingox displays all PHP errors. You might wish to change this behavior once your development is complete. You’ll find the error_reporting() function located at the top of your main index.php file. Disabling error reporting will NOT prevent log files from being written if there are errors.
Unlike most systems in Codingox, the error functions are simple procedural interfaces that are available globally throughout the application. This approach permits error messages to get triggered without having to worry about class/function scoping.
The following functions let you generate errors:
-
display_error
($status_code, $message, $title = 'Page Not Found')¶ -
Parameters: - $status_code (int) – HTTP Response status code
- $message (string) – Error message
- $title (string) – Error page title
This function will display the error message supplied to it using the error template appropriate to your execution:
views/error/404.php
-
log_error
($level, $message, $file = NULL, $line = NULL)¶ -
Parameters: - $level (int) – Log level: ‘1’, ‘2’ or ‘8’
- $message (string) – Message to log
Return type: void
This function lets you write messages to your log files. You must supply one of three “levels” in the first parameter, indicating what type of message it is (error, warning, notice), with the message itself in the second parameter.
Example:
if ($some_var == '') { log_error(1, 'Some variable did not contain a value.'); } else { log_error(2, 'Some variable was correctly set'); } log_error(3, 'The purpose of some variable is to provide some value.');
There are three message types:
- Error Messages. These are actual errors, such as PHP errors or user errors.
- Warning Messages. These are messages that assist in debugging. For example, if a class has been initialized, you could log this as debugging info.
- Notice Messages. These are the lowest priority messages, simply giving information regarding some process.