Welcome Guest, Not a member yet? Register   Sign In
Developing a multiple site application
#1

[eluser]Unknown[/eluser]
My pet project currently is based in offering a web application that manages soccer leagues. At this moment I can handle one league, that is ONE "client". That said I need to handle different server_urls for each client (multiple leagues, multiple clients) that can have their own personalized (css and images) look.

www.soccerleague1.com
www.soccerleague2.com
www.soccerleague3.com
...

My approaches:

1) Have multiple CI for each league (not quite interested in this option, lot of work to maintain)
2) Have one CI installation and handle a leages table in the DB. About this option, I think I will add the league_id to every other table (like matches, teams, etc).
Questions about option 2:
2.1) Wich would be the better way to handle the multiple sites (session, globals)? I mean, I need to get the server_url then get the league associated and then do the correspondent querys. My guess is to do something like this (hook that loads pre_controller):

Code:
class Hook {
    function get_current_league() {
        $CI =& get_instance();
        $liga = $CI->session->userdata('liga');
        if(empty($liga)){
            $CI->db->where('url',$CI->config->item('base_url'));
            $liga = $CI->db->get('ligas')->row_array();
            $CI->session->set_userdata('liga',$liga);
        }
    }
}

or
Code:
class Hook {
    function get_current_league() {
        $CI =& get_instance();
        $liga = $CI->config->item('liga')        
        if(empty($liga)){
            $CI->db->where('url',$CI->config->item('base_url'));            
            $liga = $CI->db->get('ligas')->row_array();
            $CI->config->set_item('liga',$liga);
        }
    }
}

I think the first approach is the correct one cause it defines a different variable (through session) to each user. The second one would change a global variable (config item) every time a request to a controller is done.

2.2) Is there a way to do this without using sessions? (Extending the controller maybe? but the counterpart would be repeating the query everytime against the DB).

I hope I explained myself good enough. Thanks!
#2

[eluser]2think[/eluser]
If you use option #2 which I think is better than multiple sites, why not use the URI Class to direct the users to a specific page?
#3

[eluser]n0xie[/eluser]
Why use an Hook? Might as well use a base controller which sets in which 'league' you are.
Code:
//pseudo code
class MY_Controller extends Controller {

    protected $league;        // league properties (css / theme etc)
    protected $league_id;    // league id

    function __construct()
    {
        parent::Controller();
        $this->_set_league();
    }
    
    private function _set_league()
    {
        // example, might want to use a model or session
        $query = $this->db->where('url', $this->input->server('HTTP_HOST'))->limit(1)->get('ligas');
        
        if ($query->num_rows() > 0)
        {
            $this->league         = $query->row();
            $this->league_id     = $query->row()->id;
        }
        else
        {
            show_404('site does not exists');
        }
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB