July 1st, 2005
Before you can actually handle errors, you’ll need to have your xHTML ready to slot into a PHP function. You could do this in many ways; like by hard-coding xHTML into the error handling code, but I find this to be a little cumbersome, especially if you want to use the error handling code again. I find making a page class the easiest way to avoid unnecessary code copy and pasting:
class Page
{
var $page = ''; (1)
var $title = '';
function Page ($title)
{
$this->title = $title;
$this->addHeader(); (2)
}
function addHeader()
{
$this->page.=<<<EOD (3)
<html>
<head>
<title>$this->title</title>
</head>
<body>
EOD;
}
function addCentreContent($centrecontent = ”)
{
$this->page.=<<<EOD
$centrecontent
EOD;
}
function addFooter()
{
$this->page.=<<<EOD
<p>Please contact the site admin at foo@example.com</p>
</body>
</html>
EOD;
}
function returnPage() (4)
{
return $this->page;
}
}
Look out for the last in the series, coming soon.