Hi all
Been doing a bit of study regarding php classes and objects over the past couple of nights, bit stressful but very rewarding after I’ve realized the power it can provide, never mind the convenience and how well you can structure your code.
Anyway, Ive created a class for a new html page, just wondering is this a bit over kill and should I be using a class for some like this?
I read somewhere that its wrong to have any html elements in your classes, is this right? Or are there exceptions?
class
class newPage {
var $Title;
var $Keywords;
var $Description;
var $Content;
function Display( ) {
echo "<!DOCTYPE html>\
<html lang=\\"en\\">\
<head>\
<meta charset=\\"utf-8\\">\
";
$this->DisplayTitle( );
$this->DisplayKeywords( );
echo "\
<link rel=\\"stylesheet\\" href=\\"css/global.css\\">";
echo "\
</head>\
<body>\
";
echo $this->Content;
echo "\
</body>\
</html>\
";
}
function DisplayTitle( ) {
echo "<title>" . $this->Title . "</title>\
";
}
function DisplayKeywords( ) {
echo '<meta name="keywords" content="' . $this->Keywords . '">';
echo '<meta name="description" content="' . $this->Description . '">';
}
function SetContent( $Data ) {
$this->Content = $Data;
}
}
page view
include "newPage.class.php";
$Sample = new newPage;
$Content = "<p>This page was generated by the Page Class example.</p>";
$Sample->Title = "Using Classes in PHP";
$Sample->Keywords = "PHP, Classes";
$Sample->Description = "PHP Classes Rock!";
$Sample->SetContent( $Content );
$Sample->Display( );
Any thoughts, good resources or information much appreciated
And how would you go about adding your pages content inside $Content?