'Zend_Exception' - > '注册表已初始化'

时间:2013-01-16 18:44:04

标签: php zend-framework error-handling

这是我的完整错误:

  

严格标准:访问静态属性   Bootstrap :: $ frontController as non static in   /Users/panda/Dropbox/www/_playground/myApp/Zend/Application/Resource/Frontcontroller.php   第145行

     

致命错误:带消息的未捕获异常'Zend_Exception'   “注册表已初始化”   /Users/panda/Dropbox/www/_playground/myApp/Zend/Registry.php:70 Stack   追踪:#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( '准备')   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上线   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);

}

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

谢谢!

1 个答案:

答案 0 :(得分:2)

你想用这种方法实现什么目标?

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

如果你真的想首先替换Zend_Registry的实例,请调用Zend_Registry::_unsetInstance()

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

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

但我不确定这是否必要,因为您可以从任何范围访问Zend_Registry::getInstance()。所以上面的内容与:

相同
Zend_Registry::getInstance()->set('configuration', 'myconfig');

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