Php 从数据库加载zend配置参数
在我的一个项目中(使用Zend framework),我目前正在从ini文件检索LDAP配置。我的客户希望将其更改为数据库配置 i、 例如,我想从DB中读取LDAP配置,然后将其绑定到ini文件中的其他资源参数。有没有办法做到这一点 在我的local.ini文件中,我有以下配置Php 从数据库加载zend配置参数,php,zend-framework,Php,Zend Framework,在我的一个项目中(使用Zend framework),我目前正在从ini文件检索LDAP配置。我的客户希望将其更改为数据库配置 i、 例如,我想从DB中读取LDAP配置,然后将其绑定到ini文件中的其他资源参数。有没有办法做到这一点 在我的local.ini文件中,我有以下配置 ldap.server.host = "host" ldap.server.username = "user" ldap.server.password = "pwd" ldap.server.baseDn = "DC=
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.');
}
}
有人能告诉我如何从DB中检索上述LDAP参数,然后将其绑定到Zend配置参数吗 一般算法应如下所示:
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_注册表中,所以您应该根据需要调整我的示例