代码之家  ›  专栏  ›  技术社区  ›  user8331511

Slim 3不渲染资源

  •  2
  • user8331511  · 技术社区  · 7 年前

    http://localhost:8888/css/app.css '因为严格模式下不允许使用非CSS MIME类型。

    应用程序。细枝

    <!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>
    

    {% extends 'app.twig' %}
    
    {% block content %}
        Hello from {{ appName }}!
    {% endblock %}
    

    应用程序。css

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

    screenshot

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

    1 回复  |  直到 7 年前
        1
  •  3
  •   Rob Allen    7 年前

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

    如果您使用的是内置的PHP web服务器,那么将其添加到索引顶部。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