0

我遵循了一个教程,但我的观察者没有捕捉到事件。我知道事件正在触发,因为我正在记录它们。我在我的代码中找不到错误。

/local/Package/MODULE/etc/config.xml

<config>
<modules>
    <Package_MODULE>
        <version>0.1.0</version>
    </Package_MODULE>
</modules>

<global>
    <models>
        <module>
            <class>Package_MODULE_Model</class>
        </module>
    </models>
    <events>
            <catalog_product_gallery_upload_image_after>
                    <observers>
                            <module_model_upload>
                                    <type>model</type>
                                    <class>module/observer</class>
                                    <method>printTestMessage</method>
                            </module_model_upload>
                    </observers>
            </catalog_product_gallery_upload_image_after>
    </events>

</global>
</config>

/local/Package/MODULE/Model/Observer.php

<?php

class Package_MODULE_Model_Observer{
    public function printTestMessage(Varien_Event_Observer $observer){
             Mage::log("TESTING ", null, 'events.log');  //<--same log statement I'm using to test the events firing
    }
}

/etc/modules/Package_MODULE.xml

<config>
<modules>
    <Package_MODULE>
        <active>true</active>
        <codePool>local</codePool>
    </Package_MODULE>
</modules>
</config>

EDIT2:此错误出现在 system.log 中:

2013-02-14T17:10:21+00:00 ERR (3): Notice: Uninitialized string offset: 3  in /opt/bitnami/apps/magento/htdocs/includes/src/Varien_File_Uploader.php on line 538
2013-02-14T17:10:21+00:00 ERR (3): Warning: include(/opt/bitnami/apps/magento/htdocs/includes/src/Package_MODULE_Model_Observer.php): failed to open stream: No such file or directory  in /opt/bitnami/apps/magento/htdocs/includes/src/Varien_Autoload.php on line 93
2013-02-14T17:10:21+00:00 ERR (3): Warning: include(): Failed opening '/opt/bitnami/apps/magento/htdocs/includes/src/Package_MODULE_Model_Observer.php' for inclusion (include_path='/opt/bitnami/apps/magento/htdocs/includes/src:.:/opt/bitnami/php/lib/php')  in /opt/bitnami/apps/magento/htdocs/includes/src/Varien_Autoload.php on line 93
4

2 回答 2

3

检查包含警告...这是由于启用了编译器但您的类尚未编译。

我回答这个问题的次数可能比我数的要多:禁用编译器或重新编译

于 2013-02-14T17:34:21.247 回答
0

您的观察者的配置中有错误的类名。<class>module_model/observer</class>不希望 _model 在里面。模型的类别名Package_MODULE_Model_Observermodule/observer

于 2013-02-14T17:23:57.053 回答