0

I displayed a table from database and created a delete link to every row. I want to delete a particular row when its corresponding link is clicked. Can anyone help me please..

<?php
 $model = Mage::getModel('test/test')->getCollection();
 foreach($model as $data)
  {
    echo '<tr>';
    echo '<td>'.$data->getTestId().'</td>';
    echo '<td>'.$data->getTitle().'</td>';
    echo '<td>'.$data->getFilename().'</td>';
    echo '<td>'.$data->getContent().'</td>';
    echo '<td>'.$data->getStatus().'</td>';
    echo '<td>'.$data->getCreatedTime().'</td>';
    echo '<td>'.$data->getUpdateTime().'</td>';
    ?>
    <td><a href='#'></a></td>
    <?php
    echo '</tr>';
   }
 ?>

Thanx.

1 Answer 1

0

Write a delete function in your controller. For example if you want to delete from admin panel then your delete function looks like as shown below.

public function deleteAction() 
{
    if( $this->getRequest()->getParam('id') > 0 ) {
        try {
            $model = Mage::getModel('test/test');

            $model->setId($this->getRequest()->getParam('id'))
            ->delete();

            Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
            $this->_redirect('*/*/');
        } catch (Exception $e) {
            Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            $this->_redirect('*/*/');
        }
    }
    $this->_redirect('*/*/');
}
1
  • its woirking. thanx for your help buddy.
    – Birju
    Commented Feb 15, 2017 at 6:32

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.