【问题标题】:How to include JS/CSS files into templates of Slim Framework?如何将 JS/CSS 文件包含到 Slim 框架的模板中?
【发布时间】:2013-03-14 02:39:59
【问题描述】:

我正在使用 Slim 框架开发一个简单的 Web 应用程序。我遇到了一个可能很简单的问题。我想在我的模板中包含静态文件(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) 

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

【问题讨论】:

    标签: php frameworks xampp slim


    【解决方案1】:

    我假设您在项目根目录 (index.php) 上显示您的模板,因此您应该从样式表和 JS 相关路径中删除 ../

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-29
      • 2015-08-07
      • 2018-09-14
      • 2023-03-05
      • 1970-01-01
      相关资源
      最近更新 更多