doujingke4981 2016-04-12 10:53
浏览 26
已采纳

观察者没有被Magento调用

Can some one please point out the mistake in this observer example? I have been googling and searching all the day but all in vain Here is my code for the module in magento\app\etc\modules with the name of "Meteorify_Observerexample.xml".

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

Here is my code of "config.xml" in magento\app\code\local\Meteorify\Observerexample\etc

 <?xml version="1.0"?>
<config>
    <modules>
        <Meteorify_Observerexample>
            <version>0.0.2</version>
        </Meteorify_Observerexample>
    </modules>
    <global>
        <models>
            <meteorifyobserverexample>
                <class>Observerexample_Model</class>
            </meteorifyobserverexample>
        </models>


        <events>
            <sales_order_place_before>
                <observers>
                    <Meteorify_Observerexample_Model_Observer>
                        <type>singleton</type>
                        <class>Meteorify_Observerexample_Model_Observer</class>
                        <method>example</method>
                    </Meteorify_Observerexample_Model_Observer>
                </observers>
            </sales_order_place_before>
        </events>
         </global>

</config>

Here is my code of "Observer.php" located in magento\app\code\local\Meteorify\Observerexample\Model

    <?php
class Meteorify_Observerexample_Model_Observer {

    public function example($observer) {
        //$observer contains data passed from when the event was triggered.

        Mage::log($observer);

        Mage::log('We just made an Observer!');
        echo "The event has been captured";
    }

}
?>

I have also tried by deleting the cache and log the list of events being fired by adding the Mage::log($name, null, 'events.log', true); in Mage.php file and the selected event is being fired from there.But the observer is not getting called for the given event. Any hint or help will be highly appreciated. Thanks

  • 写回答

1条回答 默认 最新

  • duanmen2189 2016-04-12 12:23
    关注

    I have figured out the mistake It was in my my 'Observer.php'. I was logging the $observer object which was producing some error.Removing that line solved the problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用