Prev | Current Page 114 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

php';
require_once BUSINESS_DIR . 'error_handler.php';
// Set the error handler
ErrorHandler::SetHandler();
// Load the application page template
require_once PRESENTATION_DIR . 'application.php';
5. Great! You just finished writing the new error-handling code. Let??™s test it. First, load the web site in your
browser to see that you typed in everything correctly. If you get no errors, test the new error-handling
system by adding the following line to index.php:
// Include utility files
require_once 'include/config.php';
require_once BUSINESS_DIR . 'error_handler.php';
// Sets the error handler
ErrorHandler::SetHandler();
// Load the application page template
require_once PRESENTATION_DIR . 'application.php';
// Display the page
$application->display('store_front.tpl');
// Try to load inexistent file
require_once 'inexistent_file.php';
?>
CHAPTER 3 ?–  STARTING THE TSHIRTSHOP PROJECT 55
Now, reload index.php in your browser, and admire your brand-new error message, shown in Figure 3-10.
Figure 3-10. Error message showing backtrace information
?– Caution Don??™t forget to remove the buggy line from index.php before moving on.
How It Works: Error Handling
The method that intercepts web site errors and deals with them is ErrorHandler::Handler() (located in
error_handler.php). The code that registers the ErrorHandler::Handler() function as the one that handles
errors in your site is in the ErrorHandler::SetHandler() method, which is invoked in index.


Pages:
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126