I have created a Page class and all the pages on my website are objects of that Page class. Each Page object has a title attribute which is passed in as an argument to the constructor and so creating a new Page object looks as follows.
<?php
require_once('library/Page.php');
$page = new Page('About');
$page->header();
This is where the problem arises.
The header() method is...
public function header()
{
require_once($this->templatePath . 'header.php');
}
I then echo the page title using
<?php echo $page->title; ?>
However, I get the following error.
Notice: Undefined variable: page in /Users/aaronfalloon/Projects/PHP/tfm/template/header.php on line 19
Notice: Trying to get property of non-object in /Users/aaronfalloon/Projects/PHP/tfm/template/header.php on line 19
Am I doing something wrong or do I need a work around to make it work?