First, let me explain my situation:
I have two domains, two websites, the same layout, but different content and different purposes.
What I would like to do:
Share between these two systems:
- The functionality, layout template and management.
What is different:
- The pages in the view, some controllers.
The options I considered:
Option 1
- Make one of the two sites a plugin
- Check the hostname: $_SERVER[‘HTTP_HOST’], and indicate in the core or bootstrap if the plugin should be used or not.
Something like this:
if ($_SERVER['HTTP_HOST'] == 'www.example1.com') {
Configure::write('defaultplugin', 'example1');
} else {
Configure::write('defaultplugin', null);
}
Is this possible
Option 2
A virtual address, but this is also hard to achieve because my routing is configured like this:
Router::connect("/{$prefix}/:language/:plugin", $indexParams, $shortParams);
Maybe I should change this route to:
Router::connect("/{$prefix}/:plugin/:language", $indexParams, $shortParams);
But if my earlier suggestion is possible, I would like to that, because I don’t know if the last solution will work correctly on some levels.
Option 3
Use the method described here: http://rickguyer.com/cakephp-one-core-many-apps/
So I would make 3 app folders: example1, example2, common. But I don’t know if it is possible to have the app folder consist of the contents of example1 and common OR example2 and common.
Option 4
An awesome idea from someone here on Stackoverflow.
Thanks in advance!
We switch our routes.php content based on the domain.
This way we have all the flexibility without having to do too much config/hacking/switching.
You just switch/replace the relevant routes and the rest should be fine.
e.g.:
You could also include/switch a whole file, if that makes it easier to read/maintain.