Magento – admin customer Edit form is not getting record id in magento

magento-1.8php-5.4phpstorm

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

Best Answer

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('adminhtml');
     $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',
        ));
    }  
...