3
가장 간단한 예제를 사용하여 Slim 3 및 Twig로 프로젝트를 만들었습니다.PHP 내장 서버는 정적 파일 대신 인덱스 페이지를 보여줍니다.
다음과- public
- index.php
- style.css
index.php
에서
응용 프로그램 코드가 될 때 : 다음과 같이
폴더 구조는
<?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();
을 이제 문제는 /style.css
를로드하려고 노력하는 대신에 메인 페이지를 표시된다, (index/index.html.twig
) . style.css
파일에 액세스 할 수없는 이유는 무엇입니까?
내가 PHP를 사용하는 서버에 내장 된 개발 서버의 명령을 사용하여 :
php -S localhost:8000 -t public public/index.php
가 어떻게 자산을로드 할 수 있습니까? 여기에 무슨 문제가 있니?