dsajkdadsa14222 2013-04-16 16:01
浏览 20

MY_Model指定数据库无法从MY_Controller工作

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

  • 写回答

1条回答 默认 最新

  • dtvnbe1428 2013-04-17 09:00
    关注

    I fixed the problem just in case anyone else comes up against the same thing.

    I moved the domain model load back into MY_Controller rather than autoloading it. This still didn't work until I moved the load of the domain model to beneath the company model (company model is using the default database) and everything then worked fine.

    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭