【问题标题】:Including CSS Zend [closed]包括 CSS Zend [关闭]
【发布时间】:2012-12-23 12:32:13
【问题描述】:

我正在尝试在名为“index.phtml”的 Zend 布局中包含一个名为“style.css”的文件。 我的文件夹树是:

    laltroposto
      |-public
      |   |-index.phtml
      |   |-css
      |   |   !-style.css
      |   !-...
      |-application
      |   |-layouts
      |   |   !-scripts
      |   |       !-index.phtml
      |   !...
      !-library
          !-...

这是我包含 css 的代码(它在 head 的标签中):

<?php echo $this->headLink()->appendStylesheet('css/style.css'); ?>

我也试过了:

<?php echo $this->headLink()->appendStylesheet('/css/style.css'); ?>

这是我的错误:

Failed to load resource: the server responded with a status of 404 (Not Found) http://www.laltroposto.com/js/jquery.js

有什么帮助吗?

【问题讨论】:

  • HTML 中的输出是什么?您在查看页面时是否收到该错误?好像这与您的 css/style.css 行无关。
  • 没有错误,它工作正常,但没有加载 css,Chrome Inspect 对我说:“GET laltroposto.com/css/style.css 404 (Not Found)”
  • 您的文档根目录是否指向 laltroposto/public?您可以发布您的 htaccess 的内容吗?
  • 抱歉,在哪里可以找到我的 htaccess?
  • 你应该有一个公开的 .htaccess 文件(除非你在其他地方有你的重写规则)。

标签: css zend-framework styles head


【解决方案1】:

我决定在 www.laltroposto.org 而不是 www.laltroposto.com 上托管我的网站...我不知道为什么!

【讨论】:

    【解决方案2】:

    你的 css 文件并没有真正的问题,但是 js 文件:jquery.js

    404 (Not Found) http://www.laltroposto.com/js/jquery.js
    

    如前所述,不要忘记在 js 加载文件的起始路径添加斜杠,否则它被视为路由并发出 404 错误页面。

    希望对你有所帮助。

    【讨论】:

      【解决方案3】:
      <?php echo $this->headLink()->appendStylesheet('css/style.css'); ?>
      

      /css/style.css = index.phtml/css/style.css

      您在 css 之前有一个额外的尾部斜杠!

      【讨论】:

      • 加载资源失败:服务器响应状态为404(未找到)laltroposto.com/js/jquery.js!好吧,据我所知,这意味着在服务器上找不到您的 jquery.js !仔细检查它是否存在!
      • 它存在,我在本地主机上,在 Apache 服务器上运行,文件就在这里! :(
      • 如果在本地主机上将该链接更改为:js/jquery.js 并从中删除 laltroposto.com/
      • 这是不正确的。路径的开头应该有一个斜线 - /css/style.css,因为在包含外部资源时,您几乎总是希望使用绝对路径而不是相对路径。
      • @AspiringAqib jquery?我不确定你的意思。
      猜你喜欢
      • 2011-06-16
      • 2014-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-10
      • 1970-01-01
      • 2010-12-07
      • 1970-01-01
      相关资源
      最近更新 更多