views:

22

answers:

2

Hi developers! I want to know what could be the best way to make multi-site with single back-end. I mean to say that I have a global shopping cart (say www.abc.com), and some regional shopping carts (say www.abc.fr, www.abc.in etc) and I want to manage them with single back-end.

Should I use a single database and site-id in my tables? Also how to maintain files?

Thanks to all.

+1  A: 

Hi sumanchalki. A little more than a year ago, Phil Sturgeon (a frequent CI contributor) wrote a great tutorial on just how to do this. See here:

http://philsturgeon.co.uk/news/2009/06/How-to-Multi-site-CodeIgniter-Set-up

treeface
+1  A: 

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 :)

Phil Sturgeon
You can of course leave the alias stuff out, that's just something I did to allow domains to be parked or redirected.
Phil Sturgeon