开发者

Magento - module with system config, how do I do something on save?

I have a simple module created with the Magento M开发者_如何学Goodule Creator with a couple of settings in admin->system->config.

When I go to these settings and choose the enable/disable option, the settings get saved - which is great - however, I want to run my own code after that, i.e. on the save action, once the data has been saved.


In your etc/system.xml add a backend model descended from Mage_Core_Model_Config_Data and use it's _afterSave() method to run your code.


although it isnt a good idea but you can achieve it by observers:

<controller_action_postdispatch_adminhtml_mymodule_mycontroller_myaction>

replace the my-s with module_controller_action, and most likely you want to put it in this event:

<controller_action_postdispatch_adminhtml_system_config_save>

in your config xml as follows:

<controller_action_postdispatch_adminhtml_system_config_save>
    <observers><myobserver>
        <type>singleton</type>
        <class>mymodule/observer</class>
        <method>mymethod</method> 
    </myobserver></observers>
</controller_action_postdispatch_adminhtml_system_config_save>

and in mymodule, as in your module have a class observer in mymodule/Model/Observer.php

and declare the observer as

class modules_mymodule_observer {
     public function myfunction(Varien_Event_Observer $observer){
         //do your stuffs
     }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜