Magento – Fetch Values in Dropdown in Custom Admin Module

magento-1.7magento-1.8

This is field i am using in Form.php

$fieldset->addField('item', 'select', array(
              'label'     => Mage::helper('frame')->__('Select Item'),
              'name'      => 'item',
              'values'    => Mage::getModel('frame')->toOptionArray(),
          ));

Here i wrote this function ..Block/Adminhtml/Frame.php

 public function toOptionArray()
    {
       $r_connection = Mage::getSingleton('core/resource')->getConnection('core_read');

            /* Write Select query */
            $sql = "SELECT * FROM manage_item";

            /* Run query*/
            $item_data = $r_connection->fetchAll($sql);

        $itemarray = array(
             array(
                'value'=>-1, 
                'label'=>'Please Select'
             )
        );
        foreach ($item_data as $itemList){
            $itemarray[] = array(
                   'value'=>$itemList['item_id'],
                   'label'=>$itemList['item_name']
            );
        }
        return $itemarray;
    }

I am getting internal server error here.any solution.

Best Answer

Mage::getModel('frame')->toOptionArray() is model class object but you have define the value at block class Block/Adminhtml/Frame so,it not works .

So you need to call function toOptionArray() using class of block class call

YouModuleNameSpace_YouModuleName_Block_Adminhtml_Frame::toOptionArray()

instead of

Mage::getModel('frame')->toOptionArray()
Related Topic