dtoqa66028 2017-02-02 08: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 08: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!

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部