sumanchalki
sumanchalki

Reputation: 1467

What can be the best way to create a multi-site in Codeigniter?

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.

Upvotes: 1

Views: 1482

Answers (2)

treeface
treeface

Reputation: 13351

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/blog/2009/06/How-to-Multi-site-CodeIgniter-Set-up

Upvotes: 1

Phil Sturgeon
Phil Sturgeon

Reputation: 30766

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

Upvotes: 3

Related Questions