3

I have created an Admin (Backend) module in Magento where i have created few text fields .. I have created the respective Model for that as well.. When i press my save button it posts the data and I can print_r the value in my Controller. Now I want to store this data into my table.. How can I do it... ?

I am writing the code something like this (Controller):-

public function postAction()
{

        $postData = $this->getRequest()->getPost();
        //print_r($postData);exit;
        $model = Mage::getModel('cod/cod');
        //print_r($model);exit;
        $model->setCodId($this->getRequest()->getParam('cod_id'))
            ->setAmount($postData['amount'])
            ->setStatus($postData['status'])
            ->save();
        Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Rule was successfully saved'));

        $this->_redirect('*/*/index');'
}

Can Anyone help me with this and I would Like to know what i need to write in my model file..

jprofitt
  • 10,874
  • 4
  • 36
  • 46
  • Is there any reason you're using a custom `setCodId()` method instead of `load()`? – jprofitt Oct 11 '11 at 12:58
  • Nope I dont have a reason... I just want to save my data into database –  Oct 11 '11 at 14:10
  • As long as you're setting up your resource model appropriately (pointing the primary key to cod_id), you should load using `load()` so the Model can be set up appropriately. I think this is probably what's causing the save issue, since other than that it looks like you're doing it correctly – jprofitt Oct 11 '11 at 14:59
  • Why `Mage::getModel('cod/cod')`? Are you magento core developer? You should use `'yourcompanyname_cod/cod'`. – Dmytro Zavalkin Oct 11 '11 at 15:27

0 Answers0