0

I have created a custom module "adminform" with some custom fields when i try to save my form data it gives the error

"Call to a member function beginTransaction()"

I have the following form fields:

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 following is my Saveaction method in controller:

 public function saveAction()
    {

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

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

        try {
        $insertId = $model->save()->getId();
        echo "Data successfully inserted. Insert ID: ".$insertId;
        } catch (Exception $e){
        echo $e->getMessage();   
        }

    return;
}

Also I have define the model in my configuration file like :

<models>
        <optfirst_reviewmycompany>
            <class>OptFirst_ReviewMyCompany_Model</class>
            <resourceModel>optfirst_reviewmycompany_resource</resourceModel>
        </optfirst_reviewmycompany>
        <optfirst_reviewmycompany_resource>
            <class>OptFirst_ReviewMyCompany_Model_Resource</class>
            <entities>
                <review>
                    <table>optfirst_reviewmycompany</table>
                </review>
            </entities>
        </optfirst_reviewmycompany_resource>
    </models>

But still no luck with data save to database is there any wrong thing i am doing please check the code and try to find the mistake that where i am doing wrong..

Thanks..

0

Your model should look like this.

<models>
  <reviewmycompany>
    <class>OptFirst_ReviewMyCompany_Model</class>
    <resourceModel>reviewmycompany_resource</resourceModel>
  </reviewmycompany>
  <reviewmycompany_resource>
    <class>OptFirst_ReviewMyCompany_Model_Resource</class>
    <entities>        
        <review>
            <table>optfirst_reviewmycompany</table>
        </review>
    </entities>
  </reviewmycompany_resource>
</models>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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