magneto--------------后台----grid中的 ----------删除功能

本文介绍如何在Magento中实现批量删除Grid中的记录。通过在Grid中添加一个'delete'操作,用户可以选择多个记录并一次性删除。该方法涉及在Grid中定义删除行为及在Controller中实现具体的删除逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击左边框,然后点击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。

 

转载于:https://www.cnblogs.com/wangzhanjianshe/archive/2011/01/30/2326695.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值