Currently I am loading multiple config files containing PHP native arrays, within my bootstrap.
require "app/configuration/config-global.php";
require "app/configuration/config-other.php";
With this setup "config-other.php" is overwriting the $settings array of "config-global.php".
Could I please get some advice on the best way to append the array within my bootstrap please.
Tim
Update
Here is a cut down version of my bootstap file setup attempting to implement Nikolaos's suggestion.
class Application extends \Phalcon\Mvc\Application
{
/**
* Register the services here to make them general or register in the ModuleDefinition to make them module-specific
*/
public function _registerServices()
{
//Define constants
$di = new \Phalcon\DI\FactoryDefault();
$loader = new \Phalcon\Loader();
$di->set('registry', function () {
return new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
});
//load our config into the registry
//$di->set('config', $config);
$this->setDI($di);
}
public function _loadConfig()
{
$di = \Phalcon\DI::getDefault();
$this->processConfig('appConfig1');
$this->processConfig('globalConfig');
// Remember config_array is the merged array in the DI container
$new_array = $di->registry->offsetGet('config_array');
// Optional, store the config in your DI container for easier use
$di->set('config', function () use ($new_array) {
return new \Phalcon\Config($config);
}
);
}
public function main()
{
$this->_registerServices();
$this->_loadConfig();
echo $this->handle()->getContent();
}
public function processConfig($name)
{
$config = array();
$di = \Phalcon\DI::getDefault();
if ($di->registry->offsetExists('config_array'))
{
$config = $di->registry->offsetGet('config_array');
}
// Now get the file from the config
require "/config/{$name}.php";
// $settings came from the previous require
$new_config = array_merge($config, $settings);
// Store it in the DI container
$di->registry->offsetSet('config_array', $new_config);
}
}
$application = new Application();
$application->main();
With the above config I get:
[02-Dec-2012 09:10:43] PHP Notice: Undefined property: Phalcon\DI\FactoryDefault::$registry in /public/frontend/index.php on line 127
[02-Dec-2012 09:10:43] PHP Fatal error: Call to a member function offsetExists() on a non-object in /public/frontend/index.php on line 127