views:

76

answers:

2

My question is based in structure and architecture really and I'm after ideas on the best way to implement the following:

I am using code igniter (although you could presume any MVC framework). I have a custom CMS which allows for the management of 5 different websites. Users log in and switch between these sites. They can add content to each of the areas of the sites. The CMS and data that can be entered is the same for each site.

The public facing sites all look completely different and represent different brands even though they contain the same data as all the others.

So how would you go about implementing these views? Are there any design patterns I should be looking at ?

The only way I can think of doing this right now is to put a switch statement inside of each controller > action to grab a different view for each website but I'm thinking there must be a much more clever way of doing this. How can I get around not producing loads of code that looks like this ?

I need a better way than this in each action...

<?php

class Home extends Controller {

    public function getPage()
    {
        $website = $this->session->userdata( "site_id" );
        switch( $website )
        {
            case "1":
                // load view one
            break;
            case "2":
                // load view 2
            break;
            // etc etc
        }
    }

}

edit: corrected $website variable

+1  A: 

You could make a class CoreController that extends Controller, and all other controllers need to extend CoreController, in your case Home. Then create folders in your view folder with site_ids, like application/views/1/, application/views/2/ and switch the base folder in the constructor of CoreController. I did something similar for another site, but I don't have the code with me right now.

Residuum
A: 

There is a way Python's Django framework handles this situation: http://docs.djangoproject.com/en/dev/ref/contrib/sites/#ref-contrib-sites In a word, (i) make sites table & model, (ii) establish habtm between Site and your existing models (iii) load Site::get_current_site() and use its attributes. What was written by Residuum seems to be a good idea for the filesystem organization.

Giorgi