Magento:观察器中的公共功能为什么不起作用? [英] Magento: why is the public function in the Observer not working?

查看:44
本文介绍了Magento:观察器中的公共功能为什么不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模块有2个文件:etc/config.xml和Model/Observer.php

I've got 2 files for my module: etc/config.xml and Model/Observer.php

Config.xml:

<config>
    <global>
        <cache>
            <types>
                <DN_js_module module="COMP_dn_js" translate="DN Cache">
                    <label>DN Cache (JS CSS)</label>
                    <description>Refresh Javascript and CSS (DN)</description>
                    <tags>COMP_DN_JSCSS</tags>
                </DN_js_module>
            </types>
        </cache>
        <events>             
            <DN_trigger>
                <observers>
                    <comp_dncache>
                        <type>singleton</type>
                        <class>dncache/observer</class>
                        <method>setCache</method>
                    </comp_dncache>
                </observers>
            </DN_trigger>
        </events>
    </global>
</config>

Observer.php:

class COMP_DNCache_Model_Observer extends Mage_Adminhtml_CacheController
{
    public function __construct(){
    }

    public function setCache($observer){
         die('test');
    }
}

因此,config.xml在Magento中的缓存列表中添加了一个额外的选项.刷新后,我希望运行公共函数setCache()并向我显示输出:'test'

So, the config.xml adds an extra option to the cache list in Magento. When it's refreshed I want the public function setCache() to run and (in this case) show me the output: 'test'

现在的问题是,没有触发setCache,并且我无法对显示进行测试":-(

Now the problem is, the setCache is not triggered and I can't get 'test' to showup :-(

推荐答案

假设您正在代码中调度事件dn_trigger

Assuming that within your code you are dispatching event dn_trigger

例如

 Mage::dispatchEvent(
     'dn_trigger',
     array('xyz' => $xyz, )
 );

Observer.php中:

class COMP_DNCache_Model_Observer
{
    public function __construct(){
    }

    public function setCache($observer){
         die('test');
    }
}

这篇关于Magento:观察器中的公共功能为什么不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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