我没有看到错误..
我在网络根目录下有一个索引文件。索引文件设置具有基本路径的数组,如下所示:
$medium = 'web';
$framework = '_magma';
$js_lib = '_lava';
$path_info = pathinfo($_SERVER['SCRIPT_NAME']);
$base_path = $path_info['dirname'];
print_r($base_path);
$paths = ['root' => $base_path,
'framework' => $framework,
'js_lib' => $js_lib,
'medium' => '/' . $medium,
'uri' => $_SERVER['REQUEST_URI']];
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($paths, $appStack->getConfig());
$app->start();
} catch (Exception $e) {
echo
'<p><b>EXCEPTION</b><br />Message: '
. $e->getMessage()
. '<br />File: '
. $e->getFile()
. '<br />Line: '
. $e->getLine()
. '</p>';
}
index 然后在“/framework/core”下实例化 BootStrap,并将上述数组传递给将其设置在类本身中的构造函数。
BootStrap 然后在“/framework/web”下实例化 StartPage,并再次通过构造函数传递路径数组。
StartPage 然后使用路径变量实例化一个设置样式表的类,该类位于“/web/stylesheets”下,如下所示:
class CssInclusion {
private $paths;
private $include_css;
public function __construct($paths, $include_css) {
// set variables
$this->paths = $paths;
$this->include_css = $include_css;
}
public function loadStylesheets() {
// set path
$directory_path = $this->paths['root'] . $this->paths['medium']. '/stylesheets';
// loop through stylesheet array
foreach ($this->include_css as $stylesheet) {
// include stylesheet, handle exceptions
$file_path = $directory_path . '/' . $stylesheet . '.css';
print_r($file_path);
try {
if (!is_file($file_path)) {
throw new Exception ('<b>Error - missing stylesheet:</b> ' . $file_path . '<br />');
}
echo '<link rel="stylesheet" type="text/css" href="' . $file_path . '" />';
} catch (Exception $e) {
echo
'<p><b>EXCEPTION</b><br />Message: '
. $e->getMessage()
. '<br />File: '
. $e->getFile()
. '<br />Line: '
. $e->getLine()
. '</p>';
}
}
}
}
我没有遇到异常,但样式表没有加载。这很奇怪。你新鲜的眼睛能看到我错过的吗?