Good morning all.
I am currently working on a project which requires dynamic switching of database and table. All my application model extends core MY_Model so that i wont have to keep re-writing my basic model functions (
create(), read(), update() and delete()).
Here is the constructor in MY_Model.
function __construct($database_connection,$table_name){
parent::__construct();
self::$database_connection = $database_connection;
self::$table_name = $table_name;
}
and a typical model has the below constructor
function __construct()
{
parent::__construct($this->load->database("db_xxx",true),"table_yyy");
}
The approach works fine but for a very major and important clashing. Neither
$this->load->model("model_name") nor
$this->load->model("model_name","object_name") returns the instance of the loaded Model class (unlike the case of loading a view
$this->load->view("view_name",array(),true)). Loading a model returns an instance of CI Loader. And also, CI does not allow re-loading of an already loaded model class.
Thus whenever i load a stack of models, the most recent model in the stack always nullify others. I want to believe there is a way around this.
I will be so glad with any assistance provided. Thanks to you all in anticipation.