Welcome Guest, Not a member yet? Register   Sign In
Multiple databases across all models without breaking reusability
#2

[eluser]pickupman[/eluser]
CI will on load one instance of an object. You can code loading a class a 100 times, and CI should load it just once. You may want to look at extending the models class (CI_Model). By extending the model class, you can add in the constructor to load both DB's. You would just need to remember to use MY_Model in any future project you would like to reuse your models in. There are some popular [url="https://bitbucket.org/jamierumbelow/codeigniter-base-model"]MY_Model[/url] files out there that build in some basic CRUD stuff.
Code:
//application/core/MY_Model.php
class MY_Model extends CI_Model{

  public function __construct(){
     parent::__construct();
     //Load DB1 stuff here

     //Load DB2 stuff here
  }
}

//In the rest of your models
class User_model extends MY_Model{
  
  public function __construct(){
    parent::__construct(); //Loads contruct from MY_Model which is loading your DB stuff
  }

  //rest of code here
}


Messages In This Thread
Multiple databases across all models without breaking reusability - by El Forum - 08-14-2011, 08:38 PM



Theme © iAndrew 2016 - Forum software by © MyBB