0

I have a non eav table with two columns namely a and b with some rows in it. I have a custom tab ,section and field in system config. Now my aim is to show all values containing in those two column in the group fields.Like a's value will be in label field and b value will be in <frontend_type> and like this it will show all the values from db in config.I searched the net regarding this I got the idea to use <frontend_model> for this but how am I suppose to return the data after calling Collection in my model and show in system.xml file. Here's my code of model

<?php
class Home_Test_Model_Adminhtml_System_Config_Source_Url
{
   public function show()
   {
       $show=Mage::getModel('test/test')
               ->getCollection()
               ->addFieldToSelect('*');

       return $show;
   }
}

EDIT: I don't want to show it as <frontend_type>select</frontend_type>. I want a long list form so <frontend_type>label</frontend_type>

a    b
a1   b1
a2   a3
..
....
......
and on
0

2 Answers 2

0

for the select you have to return toOptionArray

class Home_Test_Model_Adminhtml_System_Config_Source_Url extends Varien_Object
{
    public function toOptionArray()
    {
       $options = array();

      $show=Mage::getModel('test/test')
               ->getCollection()

       foreach($show as $coll){

        $options[] = array(
                'value'=> $coll->getFrontendLabel(),//your value
                'label' => $coll->getFrontendLabel() //your label
        );

      }



        return $options;
    }
}
2
0

Try this :

protected $_options;

    public function show($isMultiselect=false)
    {
        if (!$this->_options) {
            $this->_options = Mage::getResourceModel('test/test_collection')->loadData()->toOptionArray(false);
        }

        $options = $this->_options;
        if(!$isMultiselect){
            array_unshift($options, array('value'=>'', 'label'=> Mage::helper('adminhtml')->__('--Please Select--')));
        }

        return $options;
    }

OR

public function show()
    {
       if (!$this->_options) {
            $this->_options = Mage::getResourceModel('test/test_collection')

                ->loadData()->toOptionArray();
            array_unshift($this->_options, array('value'=> '', 'label'=> Mage::helper('adminhtml')->__('-- Please Select --')));
        }
        return $this->_options;


    }
1
  • pls check my edit
    – Akash
    Nov 27, 2015 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.