这应该很容易..有人可以为我解释一下语法吗?
我有一个控制器,它实例化一个引导类(新关键字),它实例化配置类。
然后控制器实例化一个扩展引导类的起始页类。在起始页类中,我试图访问引导(父)类中的配置对象。
这甚至可以做到吗?还是 startpage 必须直接实例化引导程序?实例化扩展引导程序的起始页是否覆盖引导程序?还是我的语法错了?
控制器(索引页)
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>';
}
引导类:
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>';
}
}
}
起始页类:
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();
}
}