codeigniter_tutorial
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
9. Error 9. Handling<br />
CodeIgniter<br />
Many times, while using application, we come across errors. It is very annoying for the<br />
users if the errors are not handled properly. CodeIgniter provides an easy error handling<br />
mechanism.<br />
You would like the messages to be displayed, when the application is in developing mode<br />
rather than in production mode as the error messages can be solved easily at the<br />
developing stage.<br />
The environment of your application can be changed, by changing the line given below<br />
from index.php file. This can be set to anything but normally there are three values<br />
(development, test, production) used for this purpose.<br />
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] :<br />
'development');<br />
Different environment will require different levels of error reporting. By default,<br />
development mode will display errors and testing and live mode will hide them.<br />
CodeIgniter provides three functions as shown below to handle errors.<br />
1. show_error() function displays errors in HTML format at the top of the screen.<br />
Syntax<br />
Parameters<br />
Return Type<br />
show_error($message, $status_code, $heading = 'An Error Was<br />
Encountered')<br />
$message (mixed) – Error message<br />
$status_code (int) – HTTP Response status code<br />
$heading (string) – Error page heading<br />
mixed<br />
2. show_404() function displays error if you are trying to access a page which does<br />
not exist.<br />
Syntax<br />
show_404($page = '', $log_error = TRUE)<br />
Parameters<br />
<br />
<br />
$page (string) – URI string<br />
$log_error (bool) – Whether to log the error<br />
Return Type<br />
void<br />
37