Welcome Guest, Not a member yet? Register   Sign In
Questions on serving same code base to multiple sites

Greetings All,

I am getting into CI for the first time.

We have chosen to use it for the redesign of our sites.
We have 4 sites for a college that essentially each site will be very very similiar.
Site layout, architecture and hierarchy will all be the same.
Page content and look and feel of each site will be different.

So I am thinking we can have one code base that will serve up pages based on which URL the user is coming from.

So I am guessing having the system folder at the same level as the www directory.
having 4 www directories all accessing the same system folder.

What are the things I am going to have to look out for and program for.
Just looking for the ideas of what I need to be on the watch out for since we are in the research and planning stage.

Blessed Be


[eluser]J Maxwell[/eluser]
If I understand you right, you are thinking of having a single system folder running 4 application folders? This is certainly possible, but you could consider doing this:

Another option would be to use a single install, then direct all of the domain names to the same place - making sure you have your Apache vhosts set up with UseCanonicalOn enabled, then set the base url to be the $_SERVER['SERVER_NAME'] variable.

This way, you'd only need to check the database for which site is being accessed, and then load the respective data/template/css etc from saved options in the database, or a config file.

In terms of DRY - this would be much better, meaning you only have a single codeset to maintain and a single change can be rolled out to the whole site effortlessly.

If you need a hand with any of it then PM me, or post here.


Can you explain your suggestion a bit further?

How exactly should the host files be setup?

If using one set of code with a config file, who would take work with a change that will only effect one of the sites?

Blessed Be


[eluser]J Maxwell[/eluser]
Before I write an explanation, just let me check I understood right the first time - what you are looking for is essentially to serve different content, through different templates, but using the same models and controllers?


Yes that is basically it.

We have 4 brands. Each brand has a different site serving a different geographically market. All sites serve up much the same content, though it each site will have different wording for SEO purposes. Each site is mostly brochureware and will have for all intents and purposes the same basic structure and site hierarchy. The only thing that will change is the brand(design/css) and the copy on the pages.

From a DRY perspective seems a waste to create 4 different sites. That is one reason I am looking at CI. To create one set of code to serve up these 4 different brands.

Blessed Be


[eluser]J Maxwell[/eluser]
Ok, thats what I thought - so:

The first thing I suggest is having a good look at DataMapper DMZ - once you use ORM, and DMZ is a lovely example of it, you won't ever want to go back.

The outline of the way I would do it is this:

Consider your database design carefully - I suggest using MySQL Workbench (free) to create ERR models which really help to visualise it.

Basically you have a site model that owns all of your other models, so say in your pages table, you can have page1 owned by site1, page 2 owned by site2 etc.

Some CI ideas:

1. Point all domain names to the same server.
2. Set your base_url in config.php to be $_SERVER['SERVER_NAME'], and consider some form of decontamination on it.
3. In your sites table save a 'domain' field with each sites details
3. In a MY_Controller, load your site into a new object -
$this->s = new Site()
4. Then from this object you can do whatever you need, for example in a posts controller, you could do:
function display($id) {
$this->s->p = new Post($id);
$this->load->view($this->s->template.'/posts', $this->s->p);
That would load a new post from the the site that was requested, then load the view 'posts.php' in the template folder defined in the original site model.

Anyway - that might give you an idea how to start out? Try searching on here for Database driven routes as well, that can offer some neat features for ensuring that each site has the desired features.

Hope that helps some!


[EDIT = error in codeblock. Ooops]

Theme © iAndrew 2016 - Forum software by © MyBB