I don’t see the error..
I have an index file under the web root. Index file sets an array with basic paths, like so:
$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 then instantiates BootStrap, under ‘/framework/core’, and passes the above array through the constructor which sets it in the class itself.
BootStrap then instantiates StartPage, under ‘/framework/web’, and passes the paths array once again through the constructor.
StartPage then instantiates a class which sets the style-sheets, located under ‘/web/stylesheets’, using the paths variable, like so:
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>';
}
}
}
}
I don’t get an exception, yet the style-sheet doesn’t load. It’s very weird. Can your fresh eyes see what I missed?
Your root path is an absolute system path like
srv/www.But a stylesheet path has to be a relative or absolute path that is accessible by the browser.
http://yoursite/cssor/cssI get my basePath like so:
Perhaps you only have to change that line:
I don’t know what
$this->paths['medium']contains?!