1

I need to add an observer in my module's config.xml file, the event is when the user press the button Save Config in System->Configuration->MyModule section of the Admin-panel. I've this in config.xml:

<global>
...
        <events>
            <admin_system_config_changed_section_sectionname>
                <observers>
                    <module_name>
                        <class>module_name/observer</class>
                        <method>handle_adminSystemConfigChangedSection</method>
                    </module_name>
                </observers>
            </admin_system_config_changed_section_sectionname>
        </events>

And this is what i have in Model/Observer.php :

<?php
class Modulename_Model_Observer
{
    public function handle_adminSystemConfigChangedSection(Varien_Event_Observer $observer)
    {
        Mage::log('Test: oberver is working!');
    }
}

When i check var/log/system.log there's nothing there. So the observer is not working. What's wrong?.

EDIT (SOLVED):

I managed to add the observer correctly.

config.xml file:

<admin_system_config_changed_section_sectionaname>
    <observers>
        <modulename>
            <type>singleton</type>
            <class>modulename/observer</class>
            <method>observersection</method>
        </modulename>
    </observers>
</admin_system_config_changed_section_sectionaname>

Observer.php:

<?php
class Modulename_Model_Observer extends Mage_Core_Model_Session_Abstract
{

    public function observersection(Varien_Event_Observer $observer)
    {
        die("");
    }
}
5
  • please add the solved part as answer and accept it to close the question
    – Sander Mangel
    Feb 19 '14 at 21:25
  • can't do that until 8 hours
    – Guille
    Feb 19 '14 at 21:27
  • ahhh and so we wait :)
    – Sander Mangel
    Feb 19 '14 at 21:33
  • @SanderMangel You are a patient man :) Jun 10 '15 at 21:13
  • @RickBuczynski jup... I guess we'll nver have the final answer
    – Sander Mangel
    Jun 11 '15 at 8:53
5

The classname should be [Namespace]_[Module]_Model_Observer, to make sure the right class is used in your config.xml you can specify the whole classname in the <class> tag.

<class>[Namespace]_[Module]_Model_Observer</class>

It might be helpful to also post the system.xml contents to see if the admin_system_config_changed_section_[sectionname] is correct.

Small suggestion. Keep your method names small and consistent. Although technically there's nothing wrong with the name using underscore and camelcase, but it may not be best practice to use underscores and camelcases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.