2014-07-15 53 views
1

在我的一个项目中(使用Zend框架),我正在从ini文件中检索LDAP配置。我的客户希望将其更改为数据库配置。从数据库加载zend config参数

即,我想从DB读取LDAP配置,然后将其绑定到ini文件中的其他资源参数。有没有办法做到这一点?

在我local.ini文件,我有以下CONFIGS

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 PARAMS将它绑定到Zend的配置参数。

回答

0

一般的算法应该是这样的:

  1. 您启动一般配置

  2. 之后,你引导数据库的初始化

  3. 然后你初始化你LDAP配置和配置进行合并

所以我加了ne XT方法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'); 
    } 
} 

注:我一直有我的配置合适的词汇,所以你应该调整我的例子您的需求。