使用zend框架在doc root之外包含一个javascript文件 [英] Including a javascript file outside of doc root using zend framework

查看:79
本文介绍了使用zend框架在doc root之外包含一个javascript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用zend框架在jmtl视图脚本文件中包含javascript文件。 javascript文件和phtml文件都是php库的一部分,位于我项目的doc根文件夹之外。所以文件结构看起来像

I'm trying to include a javascript file in a phmtl view script file using the zend framework. Both the javascript file and the phtml file are part of a php library and located outside the doc root folder of my project. So the file structure looks like

/var/www/vhosts/project/
/var/www/vhosts/libraries/my-lib/view/viewscript.phtml
/var/www/vhosts/libraries/my-lib/js/javascript.js

/ var / www / vhosts / libraries / my-lib已使用set_include_path添加到PHP路径中。在viewscript.phtml中,我使用以下行来包含javascript.js.。

/var/www/vhosts/libraries/my-lib has been added to the PHP paths using set_include_path. In viewscript.phtml, I use the following line to include javascript.js.

<?php $this->headScript()->appendFile('js/javascript.js'); ?>

由于某种原因,即使我指定绝对路径而不是a,也不包括javascript.js相对路径。相反,我在head部分的标签内获得了我的网页的完整副本。如果我将javascript.js放入doc根文件夹/ var / www / vhosts / project并更改appendFile()路径,它就可以正常工作。如何在doc root之外包含javascript?

For some reason, javascript.js is not included, even if I specify the absolute path instead of a relative path. Instead, I get a whole copy of my webpage inside a tag in the head section. If I put javascript.js into the doc root folder /var/www/vhosts/project and change the appendFile() path, it works just fine. How can I include javascript outside of doc root?

推荐答案

根据您之前提出的问题,我认为您的目录是对你有问题。
这里是Zend Framework的一个功能和安全的示例或目录组织(部分)

Based on previous questions you've been asking I think your directories are something problematic for you. here is a functionnal and secure example or directory organization for Zend Framework (partial)

var/
   www/
     vhosts/
        otherproject/
        project/
             src/ <-- maybe some project src can be here and not in your libraries
             htdocs/ <--- real apache document root
                css/
                js/
             var/
               log/
               sessions/
             etc/
             doc/
        libraries/
             Zend/
             my-lib/
                  js/

所以apache documentRoot / var / www / project / htdocs 。在这里我们可以找到index.php文件,这是公共访问中唯一可用的php文件。

So apache documentRoot is /var/www/project/htdocs. Here we can find the index.php file, the only php file available on public access.

在htdocs / js& htdocs / css你可以把你的一些项目js& css文件。然后你就得到了外部php库的css和js文件的问题,这些文件现在完全在web根目录之外。

In htdocs/js & htdocs/css you can put some of your project js & css files. And then you've got the problem of css and js files of your external php libs that are now completly outside of the web root.

我通常做的是,像其他人在这里说过,链接从外部目录到web根目录下的js目录。但是为了更加精确并在这里保持良好的组织你应该在那里做什么:

What I usually do is, like others have said here, links from external directories to the js directory inside the web root. But to be more precise and keep things well organized here what you should do there:

 ln -s /var/www/project/libraries/my-lib/js /var/www/project/htdocs/js/my-lib
 ln -s /var/www/project/libraries/my-lib/css /var/www/project/htdocs/css/my-lib

你应该为所有具有应该存在的文件的外部lib执行此操作在文档根目录中。
这样my-lib的js文件的基本URL是/ js / my-lib /.

And you should do it for all external lib having files that should be in the document root. This way the base url for the js files of my-lib is /js/my-lib/.

不要害怕使用符号链接( windows),你甚至可以将它们存储在subversion存储库中。只需检查您的apache配置是否允许符号链接(Options + FollowSymlinks)

Do not fear of using symlinks (junctions on windows), you can even store them in subversion repository. Just check that your apache configuration allow symlinks (Options +FollowSymlinks)

这篇关于使用zend框架在doc root之外包含一个javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆