magento grid 获取Ids

在后台的Grid列表中,action里面添加方法.如果要获取所选的id.有如下几种方法:

 

1,如果是js回调函数的话,这样写

grid.php中

1
2
3
4
5
6
7
8

protected function _prepareMassaction(){
$this->getMassactionBlock()->addItem('tulosta_myyntitilitykset', array(
'label' => Mage::helper('customer')->__('Tulosta myyntitilitykset'),
'callback' => 'faaraoExtcodeMassTulostaMyyntitilitykset(this, {checkedValues})'
));
//里面的{checkedValues}即为所选择的ids
}

2,如果是php直接跳转,这样写
grid.php中

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

protected function _prepareMassaction(){
$this->getMassactionBlock()->addItem('tulosta_myyntitilitykset', array(
'label' => Mage::helper('customer')->__('Tulosta myyntitilitykset'),
'url' => $this->getUrl('*/*/emptyAuctionNumber')
));
//注意,这个emptyAuctionNumber方法必须在默认的控制器中,不能自定义控制器,否则得不到ids。可以参考Mage_Adminhtml_CustomerController中的massDeleteAction()
}

public function massDeleteAction()
{
$customersIds = $this->getRequest()->getParam('customer');
if(!is_array($customersIds)) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select customer(s).'));
} else {
try {
$customer = Mage::getModel('customer/customer');
foreach ($customersIds as $customerId) {
$customer->reset()
->load($customerId)
->delete();
}
Mage::getSingleton('adminhtml/session')->addSuccess(
Mage::helper('adminhtml')->__('Total of %d record(s) were deleted.', count($customersIds))
);
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}

$this->_redirect('*/*/index');
}

坚持原创技术分享,您的支持将鼓励我继续创作!