我已经按照教程,但我的观察者没有抓住事件。我知道事件正在发生,因为我正在记录它们。我在代码中找不到错误。
/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
答案 0 :(得分:3)
检查包含警告...这是由于编译器已启用但您的类尚未编译。
我回答这个问题的次数可能比我算得多:disable the compiler or recompile。
答案 1 :(得分:0)
您的观察者配置中有错误的类名。 <class>module_model/observer</class>
不希望_model在其中。模型Package_MODULE_Model_Observer
的类别名为module/observer
。