【问题标题】:slim framework render if url add '/' then doesn't load CSS如果 url 添加 '/' 然后不加载 CSS,则苗条框架呈现
【发布时间】:2014-11-25 01:57:30
【问题描述】:

我是 PHP 初学者,是 slim 框架的新手。

这是我看完《PHP Slim Framework Simple Demo》(http://youtu.be/26CRc89gN10)后的动力。

我跟了片子也成功了,但是有个bug不知道怎么解决。

下面是我的代码:


// helloslim.php
<?
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();

$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
/*render through some template page*/
});
$app->run();
?>

  • 我用的时候效果很好

localhost/dir/helloslim.php/hello/yoyo

  • 但我使用时它不加载 css

localhost/dir/helloslim.php/hello/yoyo/

我不知道为什么?谁能告诉我?

【问题讨论】:

  • 你的网址看起来一样还是我目光短浅?
  • 第二个url后面多了个“/”

标签: php frameworks slim


【解决方案1】:

这与 Slim 无关,而是基本的 HTML。您的 css 标签类似于以下内容。

 <link media=screen href="css/styles.css" rel=stylesheet />

如果您访问的 url 是 http://example.com/foo,那么样式表将从 http://example.com/css/styles.css 访问。但是,如果 url 是 http://example.com/foo/,则 css 将从 http://example.com/foo/css/styles.css 访问。

在样式表标签中使用绝对路径。

 <link media=screen href="/css/styles.css" rel=stylesheet />

现在在这两种情况下,css 都将从http://example.com/css/styles.css 访问。

【讨论】:

  • 顺便说一句,在 XAMPP 中,我需要使用 href="./css/style.css"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多