[英]Slim Framework 404 css issue
你好,所以我在一個簡單的項目中使用slim框架,目前有一個問題。 我拋出404錯誤的代碼是:
$app->notFound(function () use ($app) {
$app->render('404.html');
});
代碼將轉到404頁面上2個未知的url參數,例如website.com/1st/2nd/
但是當有3個或更多像website.com/1st/2nd/3rd/
,代碼仍然有效,但它沒有繼續執行資產(css / js)。
我的路線配置如下:
require_once 'vendor/autoload.php';
$app = new \Slim\Slim([
'debug' => true,
'templates.path' => 'app/views'
]);
$app->view = new \Slim\Views\Twig();
$app->view->setTemplatesDirectory("app/views");
$view = $app->view();
$view->parserOptions = ['debug' => true];
$view->parserExtensions = [new \Slim\Views\TwigExtension()];
我在觀點中使用樹枝。 我按照本教程。 我的文件夾結構如下所示:
在我的基本模板中,這是我包含我的資產(css / js)的方式。
它只顯示404頁面文本。 這有什么問題嗎?
也許您應該使用base href作為css,腳本源通常是相對的。
baseUrl()是你的朋友:
<link rel="stylesheet" href="{{ baseUrl() }}/assets/css/elastislide.css" type="text/css">
使用
曾經在你的“頭”標簽中;
<head>
<base href="{{ baseUrl() }}">
</head>
然后,您可以使用這樣的相對資產網址;
<img src="/assets/img/cover.png" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.