이것은 쉽습니다. 누군가 나를위한 구문을 설명 할 수 있습니까?PHP 상위 클래스의 클래스 객체에 액세스
config 클래스를 인스턴스화하는 부트 스트랩 클래스 (new 키워드)를 인스턴스화하는 컨트롤러가 있습니다.
컨트롤러는 부트 스트랩 클래스를 확장하는 시작 페이지 클래스를 인스턴스화합니다. startpage 클래스에서 부트 스트랩 (부모) 클래스의 config 객체에 액세스하려고합니다.
이 작업을 수행 할 수도 있습니까? 또는 시작 페이지가 부트 스트랩을 직접 인스턴스화해야합니까? 부트 스트랩을 확장하고 부트 스트랩을 덮어 쓰는 시작 페이지를 인스턴스화합니까? 또는 내 구문이 잘못 되었습니까?
컨트롤러 (인덱스 페이지)
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();
}
}
'parrent :: obj' .. – Davit
'Configuration class is missing'예외가 표시됩니까? – hohner
그것을 시도했다. ** $ charset = parent :: $ config-> getCharset(); ** ... 같은 오류. – obmon