2

I am trying to add a button with a backend handler. Here's the code

Admin config: system.xml

<sync_now_button translate="label">
    <label>Sync Now</label>
    <frontend_type>button</frontend_type>                         
    <backend_model><namespace>_<module>/backend_syncnow</backend_model>
    <sort_order>40</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</sync_now_button>

Backend model: <namespace>/<module>/Model/Syncnow.php

<?php$

class <namespace>_<module>_Backend_Syncnow extends Mage_Core_Model_Config_Data
{
    public function _afterSave()
    {
        Zend_Debug::dump('sync now');
        exit;
    }
}

When I load the section associated with my configuration, I get following error -

Invalid config field backend model: <namespace>_<module>/backend_syncnow

Trace:
#0 /home/measure9/public_html/demo.smartsearch.com/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php(328): Mage::throwException('Invalid config ...')
#1 /home/measure9/public_html/demo.smartsearch.com/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php(229): Mage_Adminhtml_Block_System_Config_Form->initFields(Object(Varien_Data_Form_Element_Fieldset), Object(Mage_Core_Model_Config_Element), Object(Mage_Core_Model_Config_Element))
#2 /home/measure9/public_html/demo.smartsearch.com/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php(164): Mage_Adminhtml_Block_System_Config_Form->_initGroup(Object(Varien_Data_Form), Object(Mage_Core_Model_Config_Element), Object(Mage_Core_Model_Config_Element))
#3 /home/measure9/public_html/demo.smartsearch.com/app/code/core/Mage/Adminhtml/Block/System/Config/Edit.php(92): Mage_Adminhtml_Block_System_Config_Form->initForm()
#4 /home/measure9/public_html/demo.smartsearch.com/app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php(107): Mage_Adminhtml_Block_System_Config_Edit->initForm()
#5 /home/measure9/public_html/demo.smartsearch.com/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Adminhtml_System_ConfigController->editAction()
#6 /home/measure9/public_html/demo.smartsearch.com/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('edit')
#7 /home/measure9/public_html/demo.smartsearch.com/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#8 /home/measure9/public_html/demo.smartsearch.com/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#9 /home/measure9/public_html/demo.smartsearch.com/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#10 /home/measure9/public_html/demo.smartsearch.com/index.php(87): Mage::run('', 'store')
#11 {main}

Any pointers what could be wrong with my configuration?

Update #1: I have managed to solve my issue partially. I changed the class name from <namespace>_<module>_Backend_Syncnow to <namespace>_<module>_Model_Syncnow and I can see the button on the UI. However, the button does not show text and clicking on the button does not invoke my model.

P.S. <namespace> and <module> are just placeholders.

6
  • Would I be right to assume you have just swapped out your namespace and module name and are not actually using <namespace> and <module>? Commented Oct 24, 2014 at 15:35
  • Yes. I have some more fields above the button and they appear just fine. I am using those fields in an Observer for catalog_product_after_save event, so saving and retrieving them works fine too. Updated the question with a node. Thanks.
    – devang
    Commented Oct 24, 2014 at 15:36
  • Ok well it sounds like you have declared models in your config.xml as you have an observer so that's probably not the issue, you don't need to include the namespace when declaring the 'backend_model' - the module is determined by how you declare your models in your config.xml (which is what should be referenced when declaring your backend_model). Commented Oct 24, 2014 at 15:56
  • @JonathanHussey: If I do not specify <namespace> in <backend_model> tag, then the site complains that it was unable to load the module.
    – devang
    Commented Oct 24, 2014 at 16:20
  • Update #1: any log entries? var/log/*.log
    – Detzler
    Commented Oct 24, 2014 at 16:35

2 Answers 2

2

In Magento, there is only one button that is defined like the way you do.

Mage/Core/etc/system.xml:

<synchronize translate="label comment">
    <frontend_type>button</frontend_type>
    <frontend_model>adminhtml/system_config_system_storage_media_synchronize</frontend_model>
    <sort_order>300</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>0</show_in_website>
    <show_in_store>0</show_in_store>
    <comment>After selecting a new media storage location, press the Synchronize button
    to transfer all media to that location. Media will not be available in the new
    location until the synchronization process is complete.</comment>
</synchronize>

Look at the frontend model class.. maybe you can copy some stuff from:

app/code/core/Mage/Adminhtml/Block/System/Config/System/Storage/Media/Synchronize.php
0

Missing "Model" in:

class <namespace_<module>_Backend_Syncnow

should be

class <namespace_<module>_Model_Backend_Syncnow
2
  • It worked when I changed the class name to <namespace>_<module>_Model_Syncnow. However, now I have different issues, see my update in the question.
    – devang
    Commented Oct 24, 2014 at 16:21
  • <frontend_model> references Block folder not Model.
    – dchayka
    Commented Sep 19, 2017 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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