Initial setup of a Kohana project, revisited.

Difficulty: Easy

Hi again folks,

The last article dealt with setting up a single web application, but what if you need to set up multiple applications? For example I need to set up a site that is comprised of an administration application, a private section for our sales department and a public site.

Well its actually very easy! Using the structure defined in the original article copy and paste the applications directory for each web app your going to create, giving each a unique and meaningful name, e.g. app_sales, app_admin, etc. You should end up with something like the following:

  • app_admin    // administration application
  • app_sales     // sales application
  • app_public   // public website
  • modules
  • system
  • webroot

In your webroot directory create folders to correspond to the newly created applications. I called these folders sales and admin. In these copy/paste index.php and edit it to reflect the locations of the application, modules and system folders. e.g. $config['system'] = “../../system”; Your original index.php file in the webroot should point to where your public website resides.

Right, now simply open the config file for each application (application/config/config.php) and edit the site domain to point to your newly created folders. i.e.

app_admin/config/config.php: $config['site_domain'] = ‘localhost/admin/’;

app_sales/config/config.php: $config['site_domain'] = ‘localhost/sales/’;

app_public/config/config.php: $config['site_domain'] = ‘localhost/’;

Thats it, you now have multiple applications set up. These share the same system and modules.

The End……?

Not quite. Since all of my applications get their data from the same source, i.e. database, they all would be using the same models. Its unpractical to have a copy of each model for each application (goes against the DRY principle) so I needed a means of sharing them, I need a module!!!

So I created a module to share my models between the applications. Its very simple, create a folder in the modules directory and call it rubber_duckies (or a more meaningful name if u wish :) ). In this folder create a new directory called models. Now place any model that will be needed by the other applications in here.

  • modules / rubber_duckies / models

Finally back to the config file for each application and load your newly created module by adding it to the modules array:

$config['modules'] = array(  MODPATH . ”rubber_duckies’ , MODPATH . ‘forge’, ….. );

Thats it, you have multiple applications all sharing the same models! Go code some magic :)

Leave a Comment