The site_id approach works well too if you need a system sharing a single database, I have done this on several applications.
The best way to use this code in a MY_Controller:
$domain = $this->input->server('SERVER_NAME');
$this->load->model('sites_m');
// Check to see if a site exists
if ( ! $site = $this->sites_m->get_by('domain', $domain))
{
// Maybe this domain is an alias
if ( ! $alias = $this->sites_m->get_alias($domain))
{
show_error('This domain has not been set up yet.');
exit;
}
$site = $this->sites_m->get_by('id', $alias->site_id);
if ($alias->is_redirect)
{
redirect('http://'.$site->domain.uri_string());
}
}
$this->site =& $site;
This means in your models, views, controllers, whatever you can use $this->site->id. Or you can set a constant, whichever way you prefer :)