简体   繁体   English

AltoRouter 发送 Mime 类型

[英]AltoRouter send Mime Type

I'm using AltoRouter to route my urls to the correct files.我正在使用AltoRouter将我的 url 路由到正确的文件。 Now basically here , I describe my problem already.现在基本上在这里,我已经描述了我的问题。

On one page, I have an alert included, styled by bootstrap.在一页上,我包含了一个警报,由引导程序设计。

It's defined as simple as that:它的定义很简单:

$('#wrongPasswordDiv').html('<br/><div class="alert alert-danger" id="wrongPWAlert" role="alert">Falsches Passwort. Bitte erneut versuchen!</div>');

Also, before, Bootstrap css file is included:此外,在此之前,包含 Bootstrap css 文件:

<link rel="stylesheet" type="text/css" href="/bootstrapcss" />

bootstrapcss is routed to the correct css file using AltoRouter and this line of code: bootstrapcss使用AltoRouter和以下代码行路由到正确的 css 文件:

$router->map('GET','/bootstrapcss','vendor/twbs/bootstrap/dist/css/bootstrap.css','bootstrapcss');

Now, in console, it throws a warning saying Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/bootstrapcss" .现在,在控制台中,它会抛出一个警告,说Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/bootstrapcss"

If I use the complete path to the css file, a CDN or remove the DOCTYPE , its working fine.如果我使用 css 文件的完整路径、CDN 或删除DOCTYPE ,则其工作正常。 But I don't wanna do either of those variations... Removing the doctype, might damage other functions and if I would use the complete css path, then I wouldn't need the routing...但我不想做这些变化中的任何一个......删除文档类型,可能会损坏其他功能,如果我使用完整的css路径,那么我就不需要路由......

Any ideas how I could send the Content-type: text/css header, in order to get it working?有什么想法可以发送Content-type: text/css标头以使其正常工作吗?

You should send the proper Content-Type before you send the response content.您应该在发送响应内容之前发送正确的Content-Type I don't know much PHP so I may not read the CSS in the best way, but this is a working example:我不太了解 PHP,所以我可能不会以最好的方式阅读 CSS,但这是一个工作示例:

Using this route:使用这条路线:

$router->map('GET','/bootstrapcss','example.css','bootstrapcss');

And then while matching:然后在匹配时:

$match = $router->match();

if($match['name'] === 'bootstrapcss'){
    header("Content-Type: text/css");
    $fileName = $match['target'];
    echo file_get_contents($fileName);
    return;
}

For context, I have a full example here: https://gist.github.com/kobi/09eaeeecb3406b193a84a674218798a9对于上下文,我在这里有一个完整的例子: https : //gist.github.com/kobi/09eaeeecb3406b193a84a674218798a9
This is based on the basic example on AltoRouter: https://github.com/dannyvankooten/AltoRouter/tree/master/examples/basic这是基于 AltoRouter 上的基本示例: https : //github.com/dannyvankooten/AltoRouter/tree/master/examples/basic

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM