0

エラーが表示されません..

Web ルートの下にインデックス ファイルがあります。インデックス ファイルは、次のように基本的なパスを含む配列を設定します。

$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>';
            }
        }
    }
}

例外は発生しませんが、スタイル シートは読み込まれません。とても奇妙です。あなたの新鮮な目は私が見逃したものを見ることができますか?

4

1 に答える 1

1

ルート パスは、のような絶対システム パスですsrv/www。ただし、スタイルシート パスは、ブラウザからアクセスできる相対パスまたは絶対パスである必要があります。

http://yoursite/cssまた/css

次のように basePath を取得します。

$pathInfo = pathinfo($_SERVER['SCRIPT_NAME']);
$basePath = $pathInfo['dirname'];

おそらく、その行を変更するだけで済みます。

$directory_path = $this->paths['medium']. '/stylesheets';

$this->paths['medium']何が入っているのかわからない?!

于 2013-01-15T23:33:31.303 に答える