Magento – Custom Values in Config Dropdown

adminhtmlconfigurationmagento-1.9system.xml

I have created configuration options. It works fine but i want to add dynamic dropdown values. For that i have created select field and added source_model.

which is in

Baka/Mama/Model/System/Config/Source/Selectsand

Folder.

in system.xml file i have created Following Field.

           <selectsand>
                        <label>Dropdown</label>
                        <comment>Dropdown with global scope.</comment>
                     <frontend_type>select</frontend_type>
                     <source_model>baka_mama/system_config_source_selectsand_values</source_model>
                        <sort_order>30</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                   </selectsand>

Fatal error: Call to a member function toOptionArray() on a non-object
in
C:\xampp\htdocs\magento\includes\src\Mage_Adminhtml_Block_System_Config_Form.php
on line 463

in Values.php file i have added following code.

      class Baka_Mama_Model_System_Config_Source_Selectsand_Values{


public function toOptionArray()
{
return array(
  array('value' => 0, 'label' =>'Pizza'),
  array('value' => 1, 'label' => 'Pasta'),
  array('value' => 2, 'label' =>'Manchuriyan'),
 // and so on...
); 
}

Where am i making mistake? Need help to resolve it.

Any help would be appreciated.

Best Answer

Without having access to your source code we wont be able to definitively say where your problem likes.

The first place I would look is at the structure of your model. Can you instantiate it?

$model = Mage::getModel('baka_mama/system_config_source_selectsand_values'); echo get_class($model);

If that returns null or something other than your class then the problem likely likes in not using a correct model name, or the model file / class name combination is incorrect.

If it is being created and matches what you are expecting then post more information about the error. Especially the function where the problem is occurring as you have not identified a line number to be able to see what is happening when it gets that error.

Related Topic