Question

I'm trying to create an System configuration section with custom field values

This is my code:

system.xml

<?xml version="1.0"?>
<config>
    <tabs>
        <macerierconf translate="label">
            <label>Macerier</label>
            <sort_order>150</sort_order>
        </macerierconf>
    </tabs>
    <sections>
        <tab1 translate="label" module="adminhtml">
            <label>Settings</label>
            <tab>macerierconf</tab>
            <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>
            <groups>
                <smssending translate="label comment">
                    <label>test label</label>
                    <sort_order>60</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <device translate="label comment">
                            <label>Device</label>
                            <frontend_type>select</frontend_type>
                            <source_model>macerier_test/system_config_source_dropdown_values</source_model>
                            <sort_order>30</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                        </device>
                    </fields>
                </smssending>
            </groups>
        </tab1>
    </sections>
</config>

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Macerier_TEST>
            <version>0.1.0</version>
        </Macerier_TEST>
    </modules>
    <global>
        <models>
            <macerier_test>
                <class>Macerier_TEST_Model</class>
            </macerier_test>
        </models>
    </global>
</config>

then in Macerier\TEST\Model\System\Config\Source\Dropdown\Values.php I have this:

<?php

class Macerier_TEST_Model_System_Config_Source_Dropdown_Values
{
    public function toOptionArray()
    {
        return array(
            array(
                'value' => 'key1',
                'label' => 'Value 1',
            ),
            array(
                'value' => 'key2',
                'label' => 'Value 2',
            ),
        );
    }
}

and I get this error:

PHP Fatal error: Call to a member function toOptionArray() on a non-object in /home/user/public_html/magento/app/code/core/Mage/Adminhtml/Block/System/Config/Form.php on line 463

I am sure I'm doing something wrong here because without the custom source model the module is working.

Was it helpful?

Solution

Dropdown cannot get it Source model

macerier_test/system_config_source_dropdown_values that why it showing the error

May be you did not define model prefix.

As per as your code macerier_test . is models prefix

So let define model prefix at config.xml

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Macerier_TEST>
            <version>0.1.0</version>
        </Macerier_TEST>
    </modules>
    <!-- add this -->
    <global>
    <models>
        <macerier_test> <!-- call as model prefix identifier -->
            <class>Macerier_TEST_Model</class>
        </macerier_test>
    </models>
    </global>

</config>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top