1

Here is the form that i am using in admin form:

protected function _prepareForm()
{
    $form = new Varien_Data_Form(array(
        'id' => 'edit_form',
        'action' => $this->getUrl('*/*/save'),
        'method' => 'post',
        ));

    $form->setUseContainer(true);
    $this->setForm($form);

    $helper = Mage::helper('optfirst_reviewmycompany');
    $fieldset = $form->addFieldset('display', array('legend' => $helper->__('Select Social Icons'),
            'class' => 'fieldset-wide'));

    $fieldset->addField('facebook', 'text', array(
        'name' => 'facebook',
        'label' => $helper->__('Facebook'),
        ));
    $fieldset->addField('google', 'text', array(
        'name' => 'google',
        'label' => $helper->__('Google'),
        ));
    $fieldset->addField('twitter', 'text', array(
        'name' => 'twitter',
        'label' => $helper->__('Twitter'),
        ));
    $fieldset->addField('linkedin', 'text', array(
        'name' => 'linkedin',
        'label' => $helper->__('Linkedin'),
        ));
    $fieldset->addField('yelp', 'text', array(
        'name' => 'yelp',
        'label' => $helper->__('Yelp'),
        ));


    if (Mage::registry('optfirst_reviewmycompany')) {
        $form->setValues(Mage::registry('optfirst_reviewmycompany')->getData());
    }

    return parent::_prepareForm();
}

And here is the my save action method in controller:

public function saveAction()
    {

    //$data = $this->getRequest()->getParams();
if ( $data = $this->getRequest()->getParams() ) {

    print_r($data);

    $this->_getSession()->setFormData($data);
    $model = Mage::getModel('optfirst_reviewmycompany/review')->load(1);
    //$model = Mage::getModel('optfirst_reviewmycompany/review');
    print_r($model->getData());

    $id = $this->getRequest()->getParam('id');
    try {
        if ( $id ) {
            $model->load($id);
        }
        $model->addData($data);
        //saves data
        $model->save();

        $this->_getSession()->addSuccess(
                $this->__('Data was saved'));

        $this->_getSession()->setFormData(false);

        if ( $this->getRequest()->getParam('back') ) {
            $params = array('id' => $model->getId());
            $this->_redirect('*/*/edit', $params);
        } else {
            $this->_redirect('*/*/list');
        }
    } catch ( Exception $e ) {
        $this->_getSession()->addError($e->getMessage());
        if ( $model && $model->getId() ) {
            $this->_redirect('*/*/edit', array(
                'id' => $model->getId()
            ));
        } else {
            $this->_redirect('*/*/new');
        }
    }

    return;
}

And following is my modal:

class OptFirst_ReviewMyCompany_Model_Review extends        Mage_Core_Model_Abstract
   {
    public function _construct()
      {
        parent::_construct();
        $this->_init('optfirst_reviewmycompany/review');
      }
  }

And i am posting my model configuration as follos:

<models>
        <optfirst_reviewmycompany>
            <class>OptFirst_ReviewMyCompany_Model</class>
            <resourceModel>optfirst_reviewmycompany_resources</resourceModel>
        </optfirst_reviewmycompany>
        <optfirst_reviewmycompany_resources>
            <class>OptFirst_ReviewMyCompany_Model_Resources</class>
            <entities>
                <review>
                    <table>optfirst_reviewmycompany_icons</table>
                </review>
            </entities>
        </optfirst_reviewmycompany_resources>
    </models>

Now issue when i save form in admin its generates an error as follows:

Fatal error: Call to a member function load() on boolean in C:\xampp\htdocs\magento-new\app\code\core\Mage\Core\Model\Abstract.php on line 225

So how I can solve this error so it will save my data to database

1 Answer 1

1

you were missing the resource model

class OptFirst_ReviewMyCompany_Model_Resource_Review extends Mage_Core_Model_Resource_Db_Abstract
{

    protected function _construct()
    {
        $this->_init('optfirst_reviewmycompany/review'', 'primarykey');
    }
}
6
  • I have already defined that, sorry i didn't mentioned it earlier.. is there any issue with my config file? @Qaisar Satti
    – Xabby
    Nov 25, 2016 at 11:09
  • What will be my primarykey in current situation? I have defined as like this: $this->_init('optfirst_reviewmycompany/review', 'id_optfirst_reviewmycompany');
    – Xabby
    Nov 25, 2016 at 11:10
  • yes it is correct. did you define models in <global></global> tag Nov 25, 2016 at 11:17
  • Yes i did in global..
    – Xabby
    Nov 25, 2016 at 11:18
  • Now i got this error... Call to a member function beginTransaction()
    – Xabby
    Nov 25, 2016 at 11:22

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.