点击左边框,然后点击delete,删除grid中的记录
1
在grid中写入函数
protected function _prepareMassaction()
{
$this->setMassactionIdField('post_id');
$this->getMassactionBlock()->setFormFieldName('gao');
$this->getMassactionBlock()->addItem('delete', array(
'label' => Mage::helper('gao')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('gao')->__('Are you sure?')
));
return $this;
}
2
在grid--controller文件中写入方法:
public function massDeleteAction() {
$blogIds = $this->getRequest()->getParam('gao');
if(!is_array($blogIds)) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select post(s)'));
} else {
try {
foreach ($blogIds as $blogId) {
$blog = Mage::getModel('blog/blog')->load($blogId);
$blog->delete();
}
Mage::getSingleton('adminhtml/session')->addSuccess(
Mage::helper('adminhtml')->__(
'Total of %d record(s) were successfully deleted', count($blogIds)
)
);
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
$this->_redirect('*/*/kun');
}
redirect就是对应的grid的controller。