I'm attempting to load a database config from my module folder, but it doesn't appear to be working.
I have a module folder, with a module called "frontend" in but it doesn't get the db configuration, even if i put it in frontend/config or frontend/config/development.
I'm autoloading the module within index.php using Module::load('frontend');
Which as I said appears to be working, other than this thorny DB config issue I'm having. I was wondering if anyone knows where I'm going wrong?
You can't put database config in a module, it has to be in app/config. This is because it's read before modules are activated, and since config is cached, it will not read it again.
Harro are you certain on this? Seems strange that this would be the case, also given that I can store other config in there. If this is the case it's silly.
In that case then, is there anyway I can have one application, but run multiple sites with it (all with their own config dirs).
I just thought I'd let you know how I did this in case someone else wanted to do it.
In /app/classes I created a new folder called "database" and basically overriden the database connection class by adding a file called "connection.php" in here.
The contents of this file are:
<?php
abstract class Database_Connection extends \Fuel\Core\Database_Connection
{
public static function instance($name = null, array $config = null)
{
\Config::load('db',true);
\Config::load('frontend::db', true);
if ($name === null)
{
// Use the default instance name
$name = \Config::get('db.active');
}
if ( ! isset(static::$instances[$name]))
{
if ($config === null)
{
// Load the configuration for this database
$config = \Config::get("db.{$name}");
}
if ( ! isset($config['type']))
{
throw new \FuelException("Database type not defined in {$name} configuration");
Module files are only loaded when the module is active, which is only when you get routed to the module, either via the main request or via an HMVC request.
The db config file get's loaded on first use, so if you can construct it so that you do an HMVC call to the module before any database activity, you can load it there.