Recently I had to run two instances of NoseRub, each instance using its own configuration and database. How could this be accomplished?
My first approach was to simply check out a second copy of the app folder from the repository, and to configure it differently. It worked, but it was a pain to keep the app folders synchronized…
So I searched for a better solution. As I looked for a way to load my own version of cake/config/paths.php I suddenly remembered that you can define additional paths for controllers, models, views, etc., in app/config/bootstrap.php.
In the bootstrap.php file of the second instance I then added the following lines:
$modelPaths = array('<path to first instance>/app/models/'); $viewPaths = array('<path to first instance>/app/views/'); $controllerPaths = array('<path to first instance>/app/controllers/'); $behaviorPaths = array('<path to first instance>/app/models/behaviors/'); $helperPaths = array('<path to first instance>/app/views/helpers/'); $componentPaths = array('<path to first instance>/app/controllers/components/');
Two things are important to know (and of course I didn’t knew them at that time *g*): the paths have to end with a slash (resp. the path delimiter on your system), and if you specify for example a controller path it doesn’t mean the respective components are found automatically and so you have to define the path for the components explicitly. Same for views and helpers, and models and behaviors.
A nice side effect is that the folders for controllers, models, and views are no longer needed in the app folder, so they (plus some other folders which are not used) can be removed and we get the following structure:
/app /config /tmp /webroot app_controller.php app_model.php
You have to experiment a bit to find the structure which works for your application. And if there is still redundant stuff (e.g. in the js folder in app/webroot), then you can create symlinks for those folders.
With this solution it is relatively easy to run your application with different configurations.