php - 'Zend_Exception' -> 'Registry is already initialized'

标签 php zend-framework error-handling

这是我的完整错误:

Strict Standards: Accessing static property Bootstrap::$frontController as non static in /Users/panda/Dropbox/www/_playground/myApp/Zend/Application/Resource/Frontcontroller.php on line 145

Fatal error: Uncaught exception 'Zend_Exception' with message 'Registry is already initialized' in /Users/panda/Dropbox/www/_playground/myApp/Zend/Registry.php:70 Stack trace: #0 /Users/panda/Dropbox/www/_playground/myApp/application/Bootstrap.php(217): Zend_Registry::setInstance(Object(Zend_Registry)) #1 /Users/panda/Dropbox/www/_playground/myApp/application/Bootstrap.php(56): Bootstrap->_initSetupRegistry() #2 /Users/panda/Dropbox/www/_playground/myApp/Zend/Application/Bootstrap/BootstrapAbstract.php(669): Bootstrap->_initPrepare() #3 /Users/panda/Dropbox/www/_playground/myApp/Zend/Application/Bootstrap/BootstrapAbstract.php(622): Zend_Application_Bootstrap_BootstrapAbstract->_executeResource('prepare') 4 /Users/panda/Dropbox/www/_playground/myApp/Zend/Application/Bootstrap/BootstrapAbstract.php(586): Zend_Application_Bootstrap_BootstrapAbstract->_bootstrap(NULL) #5 /Users/panda/Dropbox/www/_playground/myApp/Zend/Application.php(355): Zend_Application_Bootstrap_BootstrapAbstract->bootstrap(NULL) #6 in /Users/panda/Dropbox/www/_playground/myApp/Zend/Registry.php on line 70



这是我的 Bootstrap 中的功能
/*
* Zend_Registry get's born here so it can be accesed
*/
protected function _initSetupRegistry()
{

    self::$registry = new Zend_Registry(array(), ArrayObject::ARRAY_AS_PROPS);
    Zend_Registry::setInstance(self::$registry);

}

如果您需要更多代码,请告诉我,我会喜欢一些查找问题的提示,或者如果有人知道确切的问题。

谢谢!

最佳答案

你想用这种方法达到什么目的?

如果您只想要一个注册表实例,请使用 Zend_Registry::getInstance() .您不应该构建它(我不确定他们为什么使用单例模式但没有将 __construct 设为私有(private))。

如果你真的想替换 Zend_Registry 的一个实例,调用 Zend_Registry::_unsetInstance()第一的。

如果您只想设置静态 $registry 变量以便稍后引用它,请尝试:

self::$registry = Zend_Registry::getInstance(); 
self::$registry->set('configuration', 'myconfig');

但我不确定这是否必要,因为您可以访问 Zend_Registry::getInstance()从任何范围。所以上面是一样的:
Zend_Registry::getInstance()->set('configuration', 'myconfig');

你可以在任何地方打电话。

关于php - 'Zend_Exception' -> 'Registry is already initialized',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14365439/

相关文章:

javascript - php代码不获取表单输入值?

php - 如何在我的 utf-8 编码页面上正确显示 utf 编码字符?

php - zend 和 htaccess 的问题

php - Zend Framework 默认值形式

PHP 不显示错误信息

php - WordPress中的HTTP错误500,这是15天内的第二次

php - 如何检查字母在PHP中是大写还是小写?

php - SQL 语法错误 id 突然为零

javascript - Koa@2 错误处理

php - Preg_Replace YouTube URL(带有或不带有开始时间变量)