1

I am new to magento, I have created custom module front and backend(admin) module, working fine except edit.

in grid bind the data correctly with id

http://localhost/magento/index.php/test/adminhtml_index/edit/id/1/key/ef47aec44d98d1201d27fcdc732243a3.

but when I click on edit I redirected to edit page and I did debug also, but record id is not getting.

public function editAction()
    {
        $testId = $this->getRequest()->getParam('test_id');
        //id is not getting
        Mage::log($testId);
        $testModel = Mage::getModel('quotes/quotes')->load($testId);
      .....
    }

if I pass/hard coded from here I got a details of record id

$testModel = Mage::getModel('quotes/quotes')->load(1);

can any one tell me where I went wrong?

thanks

2

What index did you give your entity?

$id  = $this->getRequest()->getParam('id');

I usually use id as a primary key, and am able to load it by getting the associated paramter.

As per comment:

public function editAction()
{
    $testId = $this->getRequest()->getParam('test_id');
    $testModel = Mage::getModel('quotes/quotes')->load($testId);
    $data = Mage::getSingleton('adminhtml/session')->getQuotesData(true);
    if (!empty($data)) {
        $testModel->setData($data);
    }  

    Mage::register('quotes_quotes', $testModel);
    $this->_initAction()
        ->_addContent($this->getLayout()->createBlock('quotes_quotes/adminhtml_quotes_edit')->setData('action', $this->getUrl('*/*/save')))
        ->renderLayout();
}

Then in your form file

app/code/codepool/Quotes/Quotes/Block/Adminhtml/Quotes/Edit/Form.php

...
 protected function _prepareForm()
{  
    $model = Mage::registry('wootware_inventorymanagement');
     $form = new Varien_Data_Form(array(
        'id'        => 'edit_form',
        'action'    => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('test_id'))),
        'method'    => 'post'
    ));

    $fieldset = $form->addFieldset('base_fieldset', array(
        'legend'    => Mage::helper('checkout')->__('Quotes'),
        'class'     => 'fieldset-wide',
    ));

    if ($model->getId()) {
        $fieldset->addField('id', 'hidden', array(
            'name' => 'id',
        ));
    }  
...
  • my primary key is test_id. here I am not getting record id. – Magento Nav Feb 6 '14 at 13:18
  • So when you click the record in grid view, you get directed to the edit page but the fields aren't populated with the data? – Moose Feb 6 '14 at 13:19
  • yah! if i hard code I got result otherwise not getting. – Magento Nav Feb 6 '14 at 13:20
  • see the updated answer, let me know if that proves useful – Moose Feb 6 '14 at 13:22
  • from where i write this code. – Magento Nav Feb 6 '14 at 13:23

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.