[英]Load zend config parameters from database
在我的一個項目(使用Zend框架)中,我目前正在從ini文件中檢索LDAP配置。 我的客戶希望將其更改為數據庫配置。
即,我想從數據庫讀取LDAP配置,然后將其綁定到ini文件中的其他資源參數。 有什么辦法嗎?
在我的local.ini文件中,我有以下配置
ldap.server.host = "host"
ldap.server.username = "user"
ldap.server.password = "pwd"
ldap.server.baseDn = "DC=comp,DC=com"
ldap.server.accountDomainName = "abc.intra"
ldap.server.accountDomainNameShort = "dell"
在我的引導中
protected function _initLocalConfig()
{
$globalConfig = new Zend_Config($this->getOptions(), true);
try {
$localConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/local.ini');
$globalConfig->merge($localConfig);
$this->setOptions($globalConfig->toArray());
} catch (Zend_Config_Exception $e) {
throw new Exception('File /configs/local.ini not found. Create it, it can be empty.');
}
}
有人可以告訴我如何從數據庫中檢索上述LDAP參數,然后將其綁定到Zend配置參數。
通用算法應如下所示:
您啟動常規配置
之后,您將引導數據庫初始化
然后初始化ldap配置並將其與config合並
所以我在bootstrap.php中添加了下一個方法
protected function _initConfig()
{
$config = new Zend_Config($this->getApplication()->getOptions(), true);
Zend_Registry::set('config', $config);
}
protected function _initLDAPConfig()
{
$this->bootstrap('config');
$this->bootstrap('db');
$globalConfig = Zend_Registry::get('config');
try {
/**
* Do a database query to get your ldap config from database
* and convert it to array
*/
$globalConfig->merge(new Zend_Config($ldapConfig));
} catch (Zend_Config_Exception $e) {
throw new Exception('Failed bootstraping LDAP config');
}
}
注意:我的配置始終在Zend_Registry中,因此您應該根據需要調整示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.