html - Slim 3 不渲染资源

标签 html css symfony twig slim-3

所以我试图渲染我的全局样式表,但出现错误

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

这是我的代码:

应用程序.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>

索引.twig

{% extends 'app.twig' %}

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

应用程序.css

* { box-sizing: border-box; }

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

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

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

最佳答案

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

如果您使用内置 PHP Web 服务器,请将其添加到 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

关于html - Slim 3 不渲染资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46532931/

相关文章:

css - 如何在中心和右侧对齐元素

php - Symfony2 在使用 twig 呈现文本时使用 css 删除部分文本

php - 如何在symfony中调用redirectToRoute方法接受 Controller

javascript - 如何将现有播客嵌入到我的网站中?

jquery - 实时计算 JQuery

javascript - jquery 调整大小功能不起作用

php - "Missing Service"在symfony中声明新的Topic时

javascript - Jquery 在 12 秒后显示 CSS li

html - 多个表行名称属性到 json 数组

css - WebFontLoader : Why is vanilla font-family declaration not sufficient for fallbacks?