【发布时间】:2012-10-24 04:59:38
【问题描述】:
在包含 JS 文件期间,我的新服务器上的 ZF 出现问题。 包括外部JS(google api)没问题。 看来,zf 想要加载不相关的 JS 文件。
FireBug 在 html Console 的 Srcipt Tag 中显示的错误信息:
<script src="/javascript/helper.js" type="text/javascript">
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL http://project/javascript/helper.js was not found on this server. </p>
<hr>
<address>Apache/2.2.16 (Debian) Server at domain.squeeze Port 80</address>
</body></html>
</script>
页面不加载脚本,因为它试图通过完整的 url 获取文件。由于重写规则,这不起作用。 在我尝试了数百次之后,我在同一个地方得到了这些错误:
<p>The requested URL /javascript/helper.js was not found on this server.</p>
但这是正确的相对链接。
我的结构:
/var/www/project/
-->application
-->...
-->public
-->javascript
helper.js
<other JS Files>
index.php
.htaccess
当我搜索这个错误时,我发现了这些可能的原因:
- baseURL 错误或缺失
- Mod 重写未启用
- 公开的 .htaccess 文件丢失或损坏
- vHost 中缺少“Allow Override = All”
- 文件的相对路径中没有前导“/”斜杠
它们都不适合我的问题。
- 我没有更深的“baseURL”,所以我的默认路径是“”,直接在我的 /project/public 文件夹中定向虚拟主机
- Mod 重写已启用,我可以浏览任何页面、控制器、动作
- .htaccess 是默认的并且存在
- Allow Override 设置为 All,我的重写规则适用于项目的其余部分
- 我尝试在开头不使用“/”。没有效果
我的布局有这个 JS 的包含方法: --> layout.phtml
$this->headScript()->appendFile('/javascript/jquery_1.6.2/jquery.js','text/javascript');
$this->headScript()->appendFile('/javascript/jqueryui_1.8.16/jquery-ui.min.js','text/javascript');
$this->headScript()->appendFile('/javascript/jquery.metadata.js','text/javascript');
$this->headScript()->appendFile('/javascript/jquery.validate.js','text/javascript');
$this->headScript()->appendFile('/javascript/jquery.fileupload.js','text/javascript');
$this->headScript()->appendFile('/javascript/jquery.fileupload-ui.js','text/javascript');
$this->headScript()->appendFile('/javascript/methods_de.js','text/javascript');
$this->headScript()->appendFile('/javascript/helper.js','text/javascript');*/
echo $this->headScript();
令人困惑的是,样式表包含工作。这是相同的技术
我将它们包含在
中$this->headLink()->appendStylesheet('/css/layout.css');
echo $this->headLink();
我的 .htaccess:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
我有几个 ZF 项目在 debian lenny 上运行,它们运行时没有任何问题。 现在我设置了两个 debian 挤压,在两个系统上我都遇到了这些问题。
如果我将项目文件夹复制到 lenny 系统(相同的虚拟主机配置),它工作正常。
可能有人知道我该如何解决这个问题...
非常感谢
【问题讨论】:
-
会不会是你的目录权限?
-
我找到了原因......但是,debian Squeeze 服务器(已在两次安装上测试)不想从名为“javascript”的文件夹中包含我自己尝试移动 js 文件在我的皮肤文件夹中,这有效。所以你可以说,我的 javascript 文件夹的权限设置不正确。但是错了......我将同一个文件夹“javascript”重命名为“js”,现在一切正常,包括从此路径。现在您认为文件夹路径拼写错误。错了,我新建了一个名为“javascript”的文件夹,并复制了一个js文件。
-
不可能包含,我得到了同样的错误信息。但是,如果有人遇到同样的错误,请尝试重命名您的文件夹......最好的问候......
标签: javascript zend-framework include appendfile