01-09-2008, 02:12 PM
|
#2 (permalink)
|
|
The Addict
Join Date: Jan 2008
Location: USA
Posts: 217
Thanks: 16
|
Hey, Webtuto.
There is no best way, just your way. However, some ways are easier to debug than others; object oriented helps by making self-contained "boxes" that have their own data and functions. My suggestion is that you have a header/footer template or function that you can include or call, this way you can have a function like:
PHP Code:
function error($message, $critical = false) {
if($critical === true) {
template_header();
}
echo '<div class="error"><b>Error:</b><p>'.$message.'</p></div>';
if($critical === true) {
template_footer();
exit;
}
}
In practice you might want something a little better than this, but it's a great place to start. This sort of function is best used in the procedural type of design, where you don't use objects to handle pages directly, because in the middle of writing some output or getting a query you can exit with your custom debug information.
If you do want to do something like this, you may want to have functions like this somewhere:
PHP Code:
function template_header() {
// PHP works too, if you have dynamic information in your header.
// If it isn't in a file outside the script, just make the echo
// statements here, and save it to a script that you include in
// each page.
include 'mydir/header.html';
}
function template_footer() {
include 'mydir/footer.html';
}
__________________
Programmers are in a race with the Universe to create bigger and better idiot-proof programs, while the Universe is trying to create bigger and better idiots. So far the Universe is winning. - Rich Cook
|
|
|
|