6

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.

asked Jul 7, 2015 at 9:00
4
  • can you show me config xml code? Commented Jul 7, 2015 at 9:03
  • @AmitBera I've added the config.xml source code Commented Jul 7, 2015 at 9:08
  • did you try to change your module name from TEST to Test ? Commented Jul 7, 2015 at 9:13
  • @HungDQ I don't think it matters i have an working version without Source Model the problem is somewhere in defining the model Commented Jul 7, 2015 at 9:30

1 Answer 1

7

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>
answered Jul 7, 2015 at 9:11
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.