dongye9071 2011-01-11 15:01 采纳率: 0%
浏览 44
已采纳

使用zend框架在doc root之外包含一个javascript文件

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 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'); ?>

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?

  • 写回答

4条回答 默认 最新

  • douzuanze0486 2011-01-11 16:46
    关注

    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/
    

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

    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.

    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
    

    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/.

    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)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 shape_predictor_68_face_landmarks.dat
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制