I have been working through the text book. Practical PHP by Paul Hudson.
The chapter on creating a simple OOP site. wont render in a browser. I have written the code out get not errors in the debugging console i see my rendered HTML code in the console. But in a browser i get code
setPage($page); $content = <<setContent($content); $site->render(); ?>
These are the files i have written
index.php
<?php
include 'stdlib.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
$site = new csite();
// This is a function specific to this site!
initialise_site($site);
$page = new cpage("Welcome to my site!");
$site->setPage($page);
$content = <<<EOT
Welcome to my personal web site!
EOT;
$page->setContent($content);
$site->render();
?>
I feel it has something to do with the EOT reference, as the code surrounding the EOT is what is outputted in browser.
stlib.php
<?php
function __autoload($class) {
include "$class.php";
}
function initialise_site(csite $site) {
$site -> addHeader("header.php");
$site -> addFooter("footer.php");
}
?>
csite.php
<?php
class csite {
private $headers;
private $footers;
private $page;
public function __construct() {
$this -> headers = array();
$this -> footers = array();
}
public function __destruct() {
// clean up here.
}
public function render() {
foreach ($this->headers as $header) {
include $header;
}
$this->page->render();
foreach ($this->footers as $footer) {
include $footer;
}
}
public function addHeader($file) {
$this -> headers[] = $file;
}
public function addFooter($file) {
$this -> footers[] = $file;
}
public function setPage(cpage $page) {
$this -> page = $page;
}
}
?>
cpage.php
<?php
class cpage {
private $title;
private $constant;
public function __construct($title) {
$this -> title = $title;
}
public function __destruct() {
// clean up here
}
public function render() {
echo "<H1>{$this->title}</H1>";
echo $this -> content;
}
public function setContent($content) {
$this -> content = $content;
}
}
?>
header.php and footer.php are just basic HTML code.