可能来自parse_ini_file()
[制作]
resources.cachemanager.default.frontend.name =“核心”resources.cachemanager.default.backend.name =“Memcached”resources.cachemanager.default.backend.servers.0.host =“live server 1”resources.cachemanager.default.backend.servers.0.port = 11211 resources.cachemanager.default.backend.servers.1.host =“live server 2”resources.cachemanager.default.backend.servers.1.port = 11211
[发展:生产]
resources.cachemanager.default.backend.servers.0.host =“dev server 1”resources.cachemanager.default.backend.servers.0.port = 11211
对于开发部分,您将拥有“dev server 1”和“live server 2”。 我知道有这样的结果是合乎逻辑的,但我需要以某种方式重置父树。
有什么办法吗?
答案 0 :(得分:2)
不确定这是否是你想要的,但是你可以阅读你的ini的开发部分而不继续生产,如下所示:
$conf = new Zend_Config_Ini(
APPLICATION_PATH . '/configs/application.ini',
'development',
array('skipExtends' => true) // default value is false
);
var_dump($conf->resources->cachemanager->default->backend->servers->toArray());
var_dump($conf->resources->cachemanager->default->frontend->toArray());
以上将导致:
array
0 =>
array
'host' => string 'live server 1' (length=13)
'port' => string '11211' (length=5)
// and an error because there will be no frontend if you need it.
如果您还希望使用生产中的ini值,但您不希望在开发中使用“实时服务器2”,则可以单独阅读这两个部分,从生产中取消设置服务器并将其与开发合并:< / p>
$productionIniOnly = new Zend_Config_Ini(
APPLICATION_PATH . '/configs/application.ini',
'production',
array('skipExtends' => true,'allowModifications'=>true)
);
unset($productionIniOnly->resources->cachemanager->default->backend->servers);
$developmentIniOnly = new Zend_Config_Ini(
APPLICATION_PATH . '/configs/application.ini',
'development',
array('skipExtends' => true,'allowModifications'=>true)
);
$developmentIni = $developmentIniOnly->merge($productionIniOnly);
var_dump($developmentIni->resources->cachemanager->default->backend->servers->toArray());
var_dump($developmentIni->resources->cachemanager->default->frontend->toArray());
以上将给出:
array
0 =>
array
'host' => string 'live server 1' (length=13)
'port' => string '11211' (length=5)
array
'name' => string 'Core' (length=4)
希望这对你有用。