目前,我正在引导程序中加载多个包含 PHP 本机数组的配置文件。
require "app/configuration/config-global.php";
require "app/configuration/config-other.php";
通过此设置,“config-other.php”将覆盖“config-global.php”的 $settings 数组。
我能否就在我的引导程序中附加数组的最佳方式获得一些建议。
蒂姆
更新
这是我尝试实施 Nikolaos 建议的引导文件设置的精简版本。
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();
通过上面的配置,我得到:
[02-Dec-2012 09:10:43] PHP 通知:未定义的属性:Phalcon\DI\FactoryDefault::$registry 在 /public/frontend/index.php 第 127 行
[02-Dec-2012 09:10:43] PHP 致命错误:在第 127 行的 /public/frontend/index.php 中的非对象上调用成员函数 offsetExists()