2

How to create an URL for a link (on frontend),that ,when clicked, will call a function that deletes a row from the table. Manually it works :)

public function deleteMessage($id) {
    Mage::getModel('blah/blah')->setId($id)->delete();
}
Mage::getModel('blah/blah')->deleteMessage(84);
4

You'll need to create a controller action that accepts the delete id and authenticates that the user has the privileges to delete the data in question:

class YourCompany_YourModule_IndexController extends Mage_Core_Controller_Front_Action
{
    public function deleteAction()
    {
        $id = $this->getRequest()->getParam('delete_id');

        if($this->_canDelete($id)){
            try {
                Mage::getModel('blah/blah')->setId($id)->delete();
            } catch(Exception $e) {
                Mage::getSingleton('core/session')->addError($this->__('Error occurred: %s',$e->getMessage()));
                $this->_redirectReferer();
                return;
            }
        }
        Mage::getSingleton('core/session')->addSuccess($this->__('Successfully deleted id %s',$id));


    }

    protected function _canDelete($id)
    {
        //not sure of your schema, probably something that checks if the current customer is allowed to delete:
        $customerId = Mage::getSingleton('customer/session')->getId();
        //do something
    }
}

However if this is in the admin your controller would be different and I suggest that you use the massaction delete instead.

| improve this answer | |

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.