【问题标题】:Getting a Reference to a Zend_Application's Config Object获取 Zend_Application 的配置对象的引用
【发布时间】:2023-03-14 17:25:01
【问题描述】:
是否有帮助方法/对象/方法来获取对Zend_Application 的配置资源的引用?
我知道我可以做类似的事情
$config = new Zend_Config_Ini($file, $environment);
但这会重新加载/解析配置文件。我正在寻找一种方法来查看正在运行的Zend_Application 的给定配置值。
我要解决的更大问题是我希望Zend_Queue 使用与我的默认数据库资源相同的数据库设置。如果除了“获取对配置的引用,读取资源值”之外还有更多“Zend Like”的方式来实现这一点,请随时分享!
【问题讨论】:
标签:
php
zend-framework
config
zend-application
zend-queue
【解决方案1】:
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
public function run()
{
// make the config available to everyone
$config = $this->getOptions();
Zend_Registry::set('config', new Zend_Config($config));
parent::run();
}
}
Zend_Queue
Zend_Queue_Adapter_Db __construct if (isset($this->_options['dbAdapter'])) 中有代码,所以你可以这样做
new Zend_Queue_Adapter_Db(array('dbAdapter' => Zend_Db_Table::getDefaultAdapter()));
因为标准Zend_Application_Resource_Db 可以使用配置选项resources.db.isDefaultTableAdapter = true
或者您可以将数据库适配器放入注册表并从那里在任何地方获取它
【解决方案2】:
Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOptions()