0

I have a admin back-end options section/module to control few things like upload slider images, site background, banners etc. That is simple cause it just requires xml code in system.xml. I want to add different drop-downs, radio buttons, multiple select. I have the following code in Options.php Its giving me options to select one, two or three for every drop-down, radio or multi select. What I have to define here to get different options? not just one, two and Three.

    <?php
    class Options_CustomConfig_Model_Options
    {
      /**
       * Provide available options as a value/label array
       *
       * @return array
       */
      public function toOptionArray()
      {
        return array(
          array('value'=>1, 'label'=>'One'),
          array('value'=>2, 'label'=>'Two'),
          array('value'=>3, 'label'=>'Three')                   
        );
      }
    }

3 Answers 3

0

If I understand you correctly try this:

<?php
    class Options_CustomConfig_Model_Options
    {
      /**
       * Provide available options as a value/label array
       *
       * @return array
       */
      public function toOptionArray()
      {
        return array(
          array('value'=>1, 'label'=>'One'),
          array('value'=>2, 'label'=>'Two'),
          array('value'=>3, 'label'=>'Three'),

          array('value'=>4, 'label'=>'your_name'),
          array('value'=>5, 'label'=>'another_your_name')
          // you can keep adding these lines.
        );
      }
    }

Hope this helps.

update

Right, then add following in your system.xml file where needed:

<frontend_type>select</frontend_type>
<source_model>moduleName/path_to_your_file_option</source_model>

and now create a file called option.php (you can give your own name) in model/path_to_your_file and add following:

<?php
class NameSpace_ModuleName_Model_Path_To_Your_File_Option
{
    /**
   * Provide available options as a value/label array
   *
   * @return array
   */
  public function toOptionArray()
  {
    return array(
      array('value'=>1, 'label'=>'A'),
      array('value'=>2, 'label'=>'B'),
      array('value'=>3, 'label'=>'C')                   
    );
   }
}

PS File path is very important.

7
  • No, what i mean is to have more options not just one two three in all. For example if i want 3 different drop-downs lets say one has options like 10, 100, 1000. Another drop-down with different options like A, B, C. And another like Him, Her, Them. Understand? Commented Aug 28, 2015 at 5:53
  • Check my updated answer. Commented Aug 28, 2015 at 6:00
  • No, I have all this already. Are you trying to say i should create another module with another Options.php? Commented Aug 28, 2015 at 6:02
  • You have to create diff files for those where you want different values in same module. Commented Aug 28, 2015 at 6:03
  • Well, That is another question. How? Commented Aug 28, 2015 at 6:21
0

For the a-hole who down voted.

enter image description here

in source_model customconfig/Optiontwo_options

-1

Ok so this is what needs to be done to get more options: I created another folder in Model called Optiontwo and inside Option.php. Class for options.php have to have folded in it like this: class CustomConfig_Model_Optiontwo_Options. And then in system.xml for source_model have to be declared like this: customconfig/Optiontwo_options

Thanks to Adrsh Khatri for pointing in the right direction.

0

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.