This should be easy.. can someone explain the syntax for me?
I have a controller which instantiates a bootstrap class (new keyword) which instantiates the config class.
the controller then instantiates a startpage class which extends the bootstrap class. In the startpage class I'm trying to access the config object in the bootstrap (parent) class.
Can this even be done? Or does startpage have to instantiate bootstrap directly? Does instantiating startpage that extends bootstrap, overwrite bootstrap? or is my syntax just wrong?
Controller (index page)
try {
if (!include($paths['root'] . $paths['framework'] . '/core/AutoLoader.php')) {
throw new Exception ('<b>Error - AutoLoader is missing</b>');
}
$loader = new AutoLoader($paths);
$appStack = new BootStrap($paths);
$app = new StartPage();
$app->start();
} catch (Exception $e) {
echo
'<p><b>EXCEPTION</b><br />Message: '
. $e->getMessage()
. '<br />File: '
. $e->getFile()
. '<br />Line: '
. $e->getLine()
. '</p>';
}
Bootstrap class:
class BootStrap {
protected $config;
/**
* --------------------------------------------------------------------------
** GETTERS
* --------------------------------------------------------------------------
*
*/
public function getConfig() { return $this->config; }
/**
* --------------------------------------------------------------------------
* __construct()
* PUBLIC method
* = Starts a new session, loads stylesheets, loads classes
* --------------------------------------------------------------------------
*
*/
public function __construct($paths) {
/**
* --------------------------------------------------------------------------
* load Config class
* --------------------------------------------------------------------------
*
*/
try {
if (!class_exists('Config')) {
throw new Exception ('<b>Error - Configuration class is missing</b>');
}
$this->config = new Config();
} catch (Exception $e) {
echo
'<p><b>EXCEPTION</b><br />Message: '
. $e->getMessage()
. '<br />File: '
. $e->getFile()
. '<br />Line: '
. $e->getLine()
. '</p>';
}
}
}
Startpage class:
class StartPage extends BootStrap {
/**
* --------------------------------------------------------------------------
* __construct()
* PUBLIC method
* = Starts a new session, loads stylesheets, loads classes
* --------------------------------------------------------------------------
*
*/
public function __construct() {
}
/**
* --------------------------------------------------------------------------
* Start()
* PUBLIC method
* = loads the web page
* --------------------------------------------------------------------------
*
*/
public function Start() {
// path to includes
$inc_path = $this->paths['root'] . $this->paths['medium'];
// instantiate page, html header
$charset = $this->config->getCharset();
$title = $this->config->getTitle();
$description = $this->config->getDescription();
}
}
Configuration class is missing?