I am working on a multisite system that has a "sitemanager" database and then a database per site.
In order to decide on the site database that should be loaded as well as setting up some other config stuff I have implemented MY_Controller to load information from the sitemanager database before we reach any of the main controllers.
I have already setup a couple of models to use the sitemanager database, to do this I have simply included
public function __construct()
{
$this->_db_group = 'sitemanager';
parent::__construct();
}
at the top of the model declaration and then specified the sitemanager settings in my database.php
This method works fine when I am calling the model from a standard controller, I have setup a login page to work off a table in the sitemanager database and this works fine, however, when I try to use a model that is calling the sitemanager database from within MY_Controller it doesn't work and the error message I get "Table 'translation.domains' doesn't exist" it is quite clearly trying to load my default database rather than the sitemanager one.
Can anyone tell me what I'm doing wrong? Why is the setting of the sitemanager database being ignored?
MY_Controller.php looks like this:
<?php
class MY_Controller extends CI_Controller {
function MY_Controller() {
parent::__construct();
$this->load->model('company_model');
// Get domain and load info from database
$domain_info = $this->domain_model->get_by(array('domain' => $_SERVER['HTTP_HOST']));
// Company info
$company_info = $this->company_model->get($domain_info->company_id);
// Set global variables
define('GLOBAL_COMPANY_ID',$company_info->id);
define('GLOBAL_COMPANY_NAME',$company_info->name);
}
}
Domain model looks like this:
class Domain_model extends MY_Model {
public function __construct()
{
$this->_db_group = 'sitemanager';
parent::__construct();
}
}
Thanks :)