3
最も単純な例を使ってSlim 3とTwigでプロジェクトを作成しました。次のようにPHP組み込みサーバが静的ファイルの代わりにインデックスページを表示
フォルダ構造は次のように
index.php
で
- public
- index.php
- style.css
アプリのコードは次のとおりです。
今<?php
require 'vendor/autoload.php';
$app = new \Slim\App();
$container = $app->getContainer();
// Twig
$container['view'] = function ($container) {
$view = new \Slim\Views\Twig('src/views', [
'cache' => false // TODO
]);
// Instantiate and add Slim specific extension
$basePath = rtrim(str_ireplace('index.php', '', $container['request']->getUri()->getBasePath()), '/');
$view->addExtension(new Slim\Views\TwigExtension($container['router'], $basePath));
return $view;
};
$app->get('/', function ($request, $response, $args) {
return $this->view->render($response, 'index/index.html.twig');
})->setName('index');
$app->run();
、問題は(index/index.html.twig
)/style.css
をロードしようとすると、代わりにメインページが表示されていることです。 style.css
ファイルにアクセスできないのはなぜですか?コマンドを使用して
私はそれビルトイン開発サーバPHPを使用サーバー、:
php -S localhost:8000 -t public public/index.php
どのように資産をロードすることができますか?ここで何が問題なの?