Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Dynamically bind model to specific database
  • When you wish to have a model dynamically bind to the current active database, we can do something like the following
    class Model_X extends Orm/Model
    {
      protected static $_connection;
    
      public static function connect($db)
      {
        static::$_connection = $db;
      }
    
    }
    
    Model_X::connect(Config::get('db.active'));
    

    With this set up, we can do something in a controller like:
    Config::set('db.active', $db_name); 
    

    This way, we can dynamically set the current active database and then we don't need to worry about modifying the models.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!