Slim 3 不渲染资产

Slim 3 not rendering assets

所以我正在尝试呈现我的全局样式表,但出现错误

[Error] Did not parse stylesheet at 'http://localhost:8888/css/app.css' because non CSS MIME types are not allowed in strict mode.

这是我的代码:

app.twig

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>App</title>
        <link href="https://fonts.googleapis.com/css?family=Playfair+Display" rel="stylesheet">
        <link rel="stylesheet" href="{{ base_url() }}/css/app.css">
    </head>
    <body>
        {% block content %}{% endblock %}
    </body>
</html>

index.twig

{% extends 'app.twig' %}

{% block content %}
    Hello from {{ appName }}!
{% endblock %}

app.css

* { box-sizing: border-box; }

html, body {
  font-family: 'Playfair Display', serif;
  background: yellow;
}

正如您在我的结构中看到的那样,文件就在那里 screenshot

我一直在寻找解决此问题的方法,但找不到解决方法,感谢您的帮助。

您应该将网络服务器配置为直接解析和发送 CSS 文件。

如果您使用的是内置 PHP 网络服务器,请将其添加到 index.php 的顶部:

if (PHP_SAPI == 'cli-server') {
    $_SERVER['SCRIPT_NAME'] = basename(__FILE__);
    // To help the built-in PHP dev server, check if the request was actually for
    // something which should probably be served as a static file
    $url  = parse_url($_SERVER['REQUEST_URI']);
    $file = __DIR__ . $url['path'];
    if (is_file($file)) {
        return false;
    }
}

如果您使用的是 Apache 或 Nginx,请查看 https://www.slimframework.com/docs/start/web-servers.html