我创建了一个编辑链接,想要编辑行内容并使用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('*/*/');
}
}
答案 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('*/*/');
}