Magento 1.9 Event Observer – Simple Event Observer Not Working

event-observerextensionsmagento-1.9module

even my complete module was working with default installation.


config.xml

 <?xml version="1.0"?>
    <config>
        <modules>
            <Barcatsia_Smsntf>
                <version>0.1.0</version>    <!-- Version of module -->
            </Barcatsia_Smsntf>
        </modules>
        <global>
            <blocks>
                <smsntf>
                    <class>Barcatsia_Smsntf_Block</class>  <!-- Path of the
     Block Folder, where all php files are located related to view -->
                </smsntf>
            </blocks>
            <helpers>
                <smsntf>
                    <class>Barcatsia_Smsntf_Helper</class> 
    <!-- Path of Helper Files -->
                </smsntf>
            </helpers>
    <!-- Observer event register -->
        <events>            
               <!--  <checkout_onepage_controller_success_action> -->
        <controller_action_layout_load_before>
                    <observers>
                        <Barcatsia_Smsntf_Model_Observer>
                            <type>singleton</type>
                            <class>Barcatsia_Smsntf_Model_Observer</class>
                            <method>customFunction</method>
                        </Barcatsia_Smsntf_Model_Observer>
                    </observers>
        </controller_action_layout_load_before>
               <!--  </checkout_onepage_controller_success_action> -->
            </events>
    <!-- Observer event register -->
        </global>
        <frontend>
            <routers>
                <smsntf>
                    <use>standard</use>
                    <args>
                        <module>Barcatsia_Smsntf</module>
                        <frontName>smsntf</frontName>  <!-- This is the URL
     of the module. i.e www.yourmagento.com/index.php/test will be the url of your module. -->
                    </args>
                </smsntf>
            </routers>
            <layout>  <!-- New Section Added -->
                <updates>
                    <smsntf>
                        <file>smsntf.xml</file> <!-- This is name of the layout file for this module -->
                    </smsntf>
                </updates>
            </layout>
        </frontend>
        <adminhtml>       
            <acl>
                <resources>
                    <admin>
                        <children>
                            <system>
                                <children>
                                    <config>
                                        <children>
                                            <testsection translate="title" module="smsntf">
                                                <title>SMS Notification</title>
                                            </testsection>
                                        </children>
                                    </config>
                                </children>
                            </system>
                        </children>
                    </admin>
                </resources>
            </acl>        
        </adminhtml>
    </config>

Model/observer.php

  <?php
    class Barcatsia_Smsntf_Model_Observer
    {
        public function customFunction(Varien_Event_Observer $observer)
        {
          echo "asssssssssadddddddddddddddddddddddddddddddddddddd";
        }
    }

Best Answer

Update your config.xml with following code

<?xml version="1.0"?>
<config>
    <modules>
        <Barcatsia_Smsntf>
            <version>0.1.0</version>    <!-- Version of module -->
        </Barcatsia_Smsntf>
    </modules>
    <global>
        <models>
            <smsntf>
                <class>Barcatsia_Smsntf_Model</class>
            </smsntf>
        </models>

        <blocks>
            <smsntf>
                <class>Barcatsia_Smsntf_Block</class>  <!-- Path of the
 Block Folder, where all php files are located related to view -->
            </smsntf>
        </blocks>
        <helpers>
            <smsntf>
                <class>Barcatsia_Smsntf_Helper</class> 
<!-- Path of Helper Files -->
            </smsntf>
        </helpers>
<!-- Observer event register -->
    <events>            
           <!--  <checkout_onepage_controller_success_action> -->
    <controller_action_layout_load_before>
                <observers>
                    <Barcatsia_Smsntf_Model_Observer>
                        <type>singleton</type>
                        <class>Barcatsia_Smsntf_Model_Observer</class>
                        <method>customFunction</method>
                    </Barcatsia_Smsntf_Model_Observer>
                </observers>
    </controller_action_layout_load_before>
           <!--  </checkout_onepage_controller_success_action> -->
        </events>
<!-- Observer event register -->
    </global>
    <frontend>
        <routers>
            <smsntf>
                <use>standard</use>
                <args>
                    <module>Barcatsia_Smsntf</module>
                    <frontName>smsntf</frontName>  <!-- This is the URL
 of the module. i.e www.yourmagento.com/index.php/test will be the url of your module. -->
                </args>
            </smsntf>
        </routers>
        <layout>  <!-- New Section Added -->
            <updates>
                <smsntf>
                    <file>smsntf.xml</file> <!-- This is name of the layout file for this module -->
                </smsntf>
            </updates>
        </layout>
    </frontend>
    <adminhtml>       
        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <testsection translate="title" module="smsntf">
                                            <title>SMS Notification</title>
                                        </testsection>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>        
    </adminhtml>
</config>

Rename your observer file from observer.php to Observer.php

Also disable your compilation from System > Tools > Compilation

Hope it helps you

Related Topic