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
asked Nov 27, 2015 at 12:16
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;
 }
}
answered Nov 27, 2015 at 12:27
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;
 }
answered Nov 27, 2015 at 12:22
1
  • pls check my edit Commented Nov 27, 2015 at 12:37

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.