法师注册表项"_singleton/"已经存在 [英] mage registry key "_singleton/" already exists

查看:76
本文介绍了法师注册表项"_singleton/"已经存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多关于此问题的帖子,但我想每个帖子都有不同的根源(至少从我检查过的内容来看,没有任何帮助).

I know there are lot of posts with this problem, but I guess each of them is with different roots of it (at least from what I checked - nothing helped me).

我试图在用户单击按钮时触发事件,但在浏览器警报Mage registry key "_singleton/" already exists中得到了上面提到的异常.

I am trying to fire the event upon click on a button from the user, but I get the upper mentioned exception in a browser alert Mage registry key "_singleton/" already exists.

config.xml的一部分:

The part of the config.xml:

.....
     <models>
        <packagecustomernumber>
            <class>Package_CustomerNumber_Model</class>
        </packagecustomernumber>
    </models>

</global>
<frontend>
        <events>
            <checkout_type_onepage_save_order>
                <observers>
                    <type>singleton</type>
                    <class>packageName/customernumber/observer</class>
                    <method>setCustomerNumber</method>
                </observers>
            </checkout_type_onepage_save_order>
        </events>
    </frontend>

以及类本身:

class Package_CustomerNumber_Model_Observer
{
    public function setCutomerNumber($observer)
    {
        die('setCutomerNumber');
    }
}

即使在结帐/保存订单时也应触发该按钮,因此事件应该正确.

The button which should fire the even it checking out/saving the order, so the event should be correct.

有什么建议吗?

推荐答案

弹出的第一件事就是这个

The first thing that pops out is this

<class>packageName/customernumber/observer</class>

那是无效的.这是您告诉Magento要为观察者使用的类的节点.因此,<class/>节点应该是您的观察者的完整PHP类名称

That's invalid. This is the node where you're telling Magento what class to use for your observer. As such, the <class/> node should be either the full PHP class name of your observer

<class>Package_CustomerNumber_Model_Observer</class>

或模型的类别名

<class>packagecustomernumber/observer</class>

此外,在运行观察器之前,它有助于确保您可以实例化模型类.尝试在加载了Magento的环境中运行以下代码(脚本,控制器操作,phtml模板等)

Also, before running your observer, it helps to make sure you can instantiate your model class. Try running the following code in a Magento loaded environment (script, controller action, phtml template, etc.)

$model = new Package_CustomerNumber_Model_Observer;
var_dump(get_class($model));

$model = Mage::getModel('packagecustomernumber/observer');
var_dump(get_class($model));

如果您无法实例化该类,则Magento将无法执行任何操作(并且在执行一些步骤来触发您的观察者之前先进行测试比较容易).

If you can't instantiate the class, then Magento won't be able to either (and it's easier to test this first before running through some steps to trigger your observer).

这篇关于法师注册表项"_singleton/"已经存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆