如何将JS/CSS文件包含到Slim框架的模板中


How to include JS/CSS files into templates of Slim Framework?

我正在开发一个简单的web应用程序与Slim框架。我遇到了一个可能很简单的问题。我想包含静态文件(CSS和Javascript)到我的模板。

我的项目文件夹结构如下:

index.php //<=== where all the routing happens.
/flot
      layout.css
      jquery.js
      ....
/templates
      first_template.php

我的first_template.php头文件包含:

<link href="../flot/layout.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript" src="../flot/jquery.js"></script>

当我调用项目根url

http://localhost/xampp/ProjectX/ 

(我使用XAMPP)模板显示,但css和javascript的东西不工作。Google Chrome控制台显示:

GET http://localhost/xampp/ProjectX/flot/layout.css 404 (Not Found)
GET http://localhost/xampp/ProjectX/flot/jquery.js 404 (Not Found) 

有什么建议吗?我花了将近一个小时的时间在google上搜索,但是Slim框架的整体文档仍然很精简:)

我假设你在项目根目录(index.php)上显示你的模板,所以你应该从你的样式表和JS相对路径中删除../:

<link href="flot/layout.css" rel="stylesheet" type="text/css">
<script language="javascript" type="text/javascript" src="flot/jquery.js"></script>