开发者

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

开发者 https://www.devze.com 2023-01-20 22:08 出处:网络
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 sho开发者_JAVA百科pping cart (say www.abc.com), and some regional shopping carts (

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 sho开发者_JAVA百科pping 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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消