php - AltoRouter 发送 Mime 类型
问题描述
我AltoRouter
用来将我的网址路由到正确的文件。现在基本上在这里,我已经描述了我的问题。
在一页上,我有一个警报,由引导程序设计。
它的定义很简单:
$('#wrongPasswordDiv').html('<br/><div class="alert alert-danger" id="wrongPWAlert" role="alert">Falsches Passwort. Bitte erneut versuchen!</div>');
此外,之前还包含 Bootstrap css 文件:
<link rel="stylesheet" type="text/css" href="/bootstrapcss" />
bootstrapcss
AltoRouter
使用这行代码路由到正确的 css 文件:
$router->map('GET','/bootstrapcss','vendor/twbs/bootstrap/dist/css/bootstrap.css','bootstrapcss');
现在,在控制台中,它会抛出一个警告说Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/bootstrapcss"
。
如果我使用 css 文件的完整路径、CDN 或删除DOCTYPE
,它的工作正常。但我不想做这些变化中的任何一个......删除文档类型,可能会损坏其他功能,如果我使用完整的css路径,那么我不需要路由......
有什么想法可以发送Content-type: text/css
标头以使其正常工作吗?
解决方案
您应该Content-Type
在发送响应内容之前发送正确的内容。我不太了解 PHP,所以我可能不会以最好的方式阅读 CSS,但这是一个工作示例:
使用这条路线:
$router->map('GET','/bootstrapcss','example.css','bootstrapcss');
然后在匹配时:
$match = $router->match();
if($match['name'] === 'bootstrapcss'){
header("Content-Type: text/css");
$fileName = $match['target'];
echo file_get_contents($fileName);
return;
}
对于上下文,我在这里有一个完整的示例:https
://gist.github.com/kobi/09eaeeecb3406b193a84a674218798a9 这是基于 AltoRouter 上的基本示例:https ://github.com/dannyvankooten/AltoRouter/tree/master/examples /基本的
推荐阅读
- android - MediaPlayer.create 不读取 URI
- c# - 无法解压缩较大的文件:无法作为存档打开 - 7-zip 命令行
- android - 为什么在检查textView文本是否以预期字符串结尾时android espresso测试失败(当椭圆形时)
- flutter - 颤动上的空格之间的文本
- html - 左侧带有文本的图像 HTML CSS
- javascript - MongoDB 客户端使用 async/await 连接使功能卡住
- python - Django ValueError:视图 usermanager.views.group_perm 没有返回 HttpResponse 对象。它返回 None 而不是
- css - 元素具有设定的高度,如果内部元素溢出 Y - 转移到新列
- r - 如何将统计测试的结果作为绘图表达式包含在 ggplot2 facet 中
- laravel-5.7 - 我的 Laravel Schedule withoutOverlapping() 不适用于 runInBackground()