I have this class, and I was wondering, do you consider it a waste? As in should I do this? I understand how class’s work and what makes them good but im failing (in a website point of view) to understand what use they have.
<?
class PageHandler {
var $html;
function header () {
$this->html .= "<html>
<head>
<title>Nuclear Summer</title>
</head>
<body>";
}
function footer () {
$this->html .= "
</body>
</html>
";
}
function input ($html) {
$this->html .= $html;
}
function output () {
echo $this->html;
}
}
?>
Yes.
This is a bad use of a class. What you’re using a class for is what you should be using views for (if you’re going for a MVC approach, which is a good way to go).
You create a main
layoutview, which contains code common to all pages (e.g. header, footer) and then you route incoming requests to an appropriate controller, which fills in the “middle” of the layout with appropriate content.CodeIgniter is a great PHP framework for getting to grips with MVC. It even has documentation on it.