dtoqa66028 2017-02-02 16:40
浏览 46
已采纳

PHP - 如何使用多个Web应用程序导入资产

everyone. How are you all?

I'm a beginner at PHP, and I was hoping you could help me with something. I have two web applications that used to be independent from one another. Now, however, there's the need for them to run in the same server, share the same database and so on.

I thought the best (and more organized) way to do this would be to use a new index.php that require the index.php from each of these applications, but I'm having trouble importing their CSS and JAVASCRIPT correctly.

So, here's the thing:

I had two web applications with the following structure:

bower_components/
templates/
images/
scripts/
index.php

(It's actually larger than this, but the idea is the same).

I tried this, then:

webapp1/
webapp2/
index.php

(webapp1 and webapp2 both have the structure presented above).

My index.php is something like this:

<?php
require_once 'webapp1/index.php';
require_once 'webapp2/index.php';
?>

That... Somewhat works. But then the applications can't correctly import the files from bower_components, for instance. These files are imported in a header.html file located in templates folder. The code is something like this:

<script src="../bower_components/jquery/dist/jquery.min.js"></script>
<script src="../bower_components/owl.carousel/dist/owl.carousel.min.js"></script>
<script src="../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>

Used to work just fine when they were, in fact, independent. Now, not so much.

It would work if I changed these to:

<script src="../webapp1/bower_components/jquery/dist/jquery.min.js"></script>

BUT!! I don't want to do that. It's a lot of changes to be made, across a lot of files, there has to be a simpler way.

Anyway, so sorry for the long question, hope it was clear enough. So, is there a way to do this without changing the html files?

Thank you in advance.

Additional notes: I'm running them in the simple PHP built in server, but have Apache available (just didn't want to use it). I'm using SLIM framework in one of them.

  • 写回答

1条回答 默认 最新

  • douren2395 2017-02-02 16:51
    关注

    You would need to configure your web server.

    Apache example configuration:

    # Ensure that Apache listens on port 80
    Listen 80
    <VirtualHost *:80>
        DocumentRoot "/www/example1"
        ServerName www.example.com
    
        # Other directives here
    </VirtualHost>
    
    <VirtualHost *:80>
        DocumentRoot "/www/example2"
        ServerName www.example.org
    
        # Other directives here
    </VirtualHost>
    

    And than you can have them as 2 separate applications one in folder /www/example2 another /www/example1 with own set of libraries each.

    For Nginx see tutorial

    It is actually not a good idea to share code components from one app to another directly. They can use same library and same version but I would still have 2 copies of them, disk space is cheap!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误