I’m sure this is easy, but I’m totally stuck here.
I’m using sf2 to make a site with multiple “applications”, but I want a mainpage to display some kind of index of them and I’m not sure on how to do this. Let’s think of this example (actually, it’s not what I’m doing but we could use this):
I have a page for some video game consoles (for now, PS3, 360, WII, PSV and NDS). They will be located in sites like ps3.domain.com, 360.domain.com, nds.domain.com and so on. Every one of them is actually different in it’s logics, they are not clones (one “app” for every one of them), they are mostly independent, except for the core and the user/community stuff, which they are sharing. But in http://www.domain.com or just domain.com, I need to have links to all of them, and I’m not sure where to put this, or how to make a “global” controller above all others.
Could somebody help me?
If your applications are really different, here how I’d do:
Structure:
Perhaps a better thing, add all console bundles inside a “Console” repository:
CoreBundle is used to share entities between the other bundles, but not only: it will be the bundle that contains specific part of templates that are include on all bundles.
After, you create one web controller per console:
See inside app_ps3.php, replace the first param of AppKernel constructor by the name of the console:
You can duplicate each controller in dev version if you want, like app_dev.php…
Now, the framework will load different environment depending of the used webcontroller.
For example, your domain “ps3.domain.com” will use web/app_ps3.php (we will see how to do that at the end).
The framework will load the config of the app in app/AppKernel.php:
If the visitor hit web/app_ps3.php, the framework will load config_ps3.yml instead of the classical config_dev.php or config_prod.php. You’ll now play with bundle dependencies !
Create for each console a “app/config_myconsole.php” and also a “app/routing_myconsole.yml”.
In config_ps3.yml (and other consoles), load your general config:
After this line override the routing inclusion for ps3 routing file:
To resume, if a user hit web/app_ps3.yml, the file config_ps3.yml is loaded, then the general config.yml file, then routing_ps3.yml (which replace routing.yml).
You can also just import the config of the wanted bundle, for each config file, this can lighten the load if you have many bundles:
Each console application used is own routes, and also some shared routes and actions located in CoreBundle.
For each application, you need to load its console routes and the corebundle routes, here an example of routing_ps3.yml:
If the user hit web/app_ps3.yml, routes from Ps3Bundle and CoreBundle are loaded…
If the user is on http://ps3.domain.com/, il will hit the route “/” from Ps3Bundle, and not the route “/” from another console or from the portal bundle, because you don’t load them !
If you’ve got a generic page, like “/stats/”, that is shared between all applications, just create this route in CoreBundle, so that you don’t have to duplicate the code on each bundle. As you included CoreBundle routes with Ps3Bundle, the framework will search the route in both bundles.
This route will be accessible here: ps3.domain.com/stats/, xbox.domain.com/stats/…
To finish, the last thing you need to do is to use the right webcontroller depending on the subdomain, here how to process:
I’m not really comfortable with vhosts, but normally it works !
So that’s it, you know how to play with different config to load different applications built on the same core !
Cheers.