Question

I'm trying to add a button in the admin section, but I'm facing an annoying problem. to be quick, Magento doesn't resolve the path to my <frontend_model>, it try to look into Mage_Mymodule_Block_Button instead of Mynamespace_Mymodule_Block_Button.

I have this error message:

Fatal error: Class 'Mage_Mymodule_Block_Button' not found in [...]\app\code\core\Mage\Core\Model\Layout.php on line 590

Here's some more information:

app/code/local/Mynamespace/Mymodule/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Mynamespace_Mymodule>
            <version>1.0</version>
        </Mynamespace_Mymodule>
    </modules>

    <global>
        <models>
            <Mymodule>
                <class>Mynamespace_Mymodule_Model</class>
            </Mymodule>                         
        </models>

        <helpers>
            <Mymodule>
                <class>Mynamespace_Mymodule_Helper</class>
            </Mymodule>
        </helpers>
    </global>

    <adminhtml>
        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <section1>
                                            <title>Section 1</title>
                                        </section1>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>
    </adminhtml>
</config>

app/code/local/Mynamespace/Mymodule/etc/system.xml

<config>
    <tabs>
        <mymodule translate="label" module="mymodule">
            <label>My Module</label>
            <sort_order>210</sort_order>
        </mymodule>
    </tabs>
    <sections>
        <section1 translate="label" module="mymodule">
            <class>separator-top</class>
            <label>Section 1</label>
            <tab>mymodule </tab>
            <frontend_type>text</frontend_type>
            <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>
            <groups>
                <group1 translate="label">
                    <label>Group 1</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>100</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <run translate="label">
                            <label>Run it</label>
                            <frontend_type>button</frontend_type>
                            <frontend_model>mymodule/button</frontend_model>
                            <sort_order>10</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </run>
                    </fields>
                </group1>
            </groups>
        </section1>
    </sections>
</config>

app/code/local/Mynamespace/Mymodule/Block/Button.php

class Mynamespace_Mymodule_Block_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
{

    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {
        $this->setElement($element);
        $url = $this->getUrl('mymodule/admin/initialize');

        $html = $this->getLayout()->createBlock('adminhtml/widget_button')
                    ->setType('button')
                    ->setClass('scalable')
                    ->setLabel('Initialize')
                    ->setOnClick("setLocation('$url')")
                    ->toHtml();

        return $html;
    }
}

Any idea to help me ? Thanks

Was it helpful?

Solution

Can you try to add following under global tag in config.xml:

<blocks>
     <Mymodule>
         <class>Mynamespace_Mymodule_Block</class>
     </Mymodule>                         
 </blocks>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top