单击magento中的编辑链接时删除特定行

时间:2017-02-17 04:52:49

标签: magento

我创建了一个编辑链接,想要编辑行内容并使用magento将更改保存到数据库。我创建了正常工作的删除链接

if( $this->getRequest()->getParam('class') > 0 ) {


    try {
        $model = Mage::getModel('test/test');

        $model->setId($this->getRequest()->getParam('class'))
        ->setTitle('new title')->setUpdateTime(strtotime('now'))->save();

        Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully edited'));
        $this->_redirect('*/*/');
    } catch (Exception $e) {
        Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
        $this->_redirect('*/*/');
    }
}

1 个答案:

答案 0 :(得分:0)

如果你想删除行,那么在控制器中添加以下操作,希望这会有所帮助。

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

                $model->setId($this->getRequest()->getParam('class'))
                    ->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('*/*/');
    }