Symfony 2 multiple apps?

后端 未结 6 1545
灰色年华
灰色年华 2021-01-31 12:06

This appears to be the scariest topic relating to Symfony2, as after a week of searching and testing, I am still unable to find an answer to this.

In short, I am buildin

相关标签:
6条回答
  • 2021-01-31 12:39

    Basically Fabien is right, there's no reason to have more than one application, if you really have a need for a different application it's probably a different project. Bundles and libraries can be easily shared like any other bundle you see on the web. Then you can have the small part of the set up belonging to each thing you call "app" in the app part of each project. If they share the entirety of the code then it's just a matter of configuration hierarchy for each sub-domain, which could be your case considering you want to share some part of the config.

    Symfony has many ways of allowing you to reutilise code which are very nice, but the framework is not meant to have many applications, if you want to try to hack it, go ahead, but then you're not using the framework anymore. And that's why you can't find examples, not because it's scary, it'd not be that hard to modify, it'd just be ugly, IMO.

    0 讨论(0)
  • 2021-01-31 12:42

    You can create different configuration using the testing/Dev example :

    Step 1 Create as many web/app.php file as you have subdomain.

    web/app_subdomainx.php
    

    Step 2 In each app_subdomain_X.php file change configuration :

    $kernel = new AppKernel('subdomainx', false);
    

    Step 3 create configuration file matching your environment

    config_subdomainx.yml
    security_subdomainx.yml
    

    Step 4

    acces you specific domain through

    /web/app_subdomainx.php

    PS :

    Keep config.yml for common configuration (like db connection) and include config.yml into config_subdomainx.yml

    imports:
        - { resource: config.yml }
    
    0 讨论(0)
  • 2021-01-31 12:42

    Maybe you can try this bundle, that handle multiple domain website on same app and database: https://github.com/AppVentus/MultiDomainBundle.

    0 讨论(0)
  • 2021-01-31 12:49

    you can try to find something on github. I've found the following Bundle which should do this. Imikay RouterBundle

    0 讨论(0)
  • 2021-01-31 12:58

    Sorry for necroing...

    I just want to say that I have looked into multiple application structure for Symfony2 as well. Since version 2.4, when routing supported hostname based routing, there has been no need for multiple apps.

    All you now need to do is separate your "apps" into different bundles, say AcmeSiteBundle and AcmeApiBundle, then in app/config/routing.yml:

    acme_site:
        host:     "www.{domain}"
        resource: "@AcmeSiteBundle/Resources/config/routing.yml"
        prefix:   /
        defaults:
            domain: "%domain%"
        requirements:
            domain: "%domain%"
    
    acme_api:
        host:     "api.{domain}"
        resource: "@AcmeApiBundle/Resources/config/routing.yml"
        prefix:   /
        defaults:
            domain: "%domain%"
        requirements:
            domain: "%domain%"
    

    Remember to have domain parameter set in app/config/parameters.yml

    parameters:
        .....
        domain: example.com
    
    0 讨论(0)
  • 2021-01-31 13:02

    Multiple applications projects can be achieved by splitting your code in multiple Kernels.

    You can then benefit:

    • multiple web roots (useful for differents domains)
    • shared & specific config (via imports)
    • clean separation of Bundles...

    I have described the whole process here: http://jolicode.com/blog/multiple-applications-with-symfony2 and you can find an example distribution here: https://github.com/damienalexandre/symfony-standard

    0 讨论(0)
提交回复
热议问题