我想要的是更改“添加新”按钮的操作
class World_Exporter_Block_Adminhtml_Attribute extends Mage_Adminhtml_Block_Widget_Grid_Container{
public function __construct()
{
$location = str_replace('new', 'newMap', $this->getCreateUrl());
$this->_controller = 'adminhtml_attribute';
$this->_blockGroup = 'exporter';
$this->_headerText = Mage::helper('exporter')->__('Attribute Manager ');
$this->_addButtonLabel = Mage::helper('exporter')->__('Add Item');
parent::__construct();
$this->setCreateUrl($location);
$this->_addButton('add', array(
'label' => $this->getAddButtonLabel() ,
'onclick' => 'setLocation(\'' . $location .'\')',
'class' => 'add',
));
// echo $this->getCreateUrl();
}
}
在尝试了这么多之后,我仍然可以将“newAction”更改为任何其他.. Plz帮助
答案 0 :(得分:7)
Yevgeny的答案很好,但我会在他的代码中改变一些小东西:
public function __construct()
{
$this->_controller = 'adminhtml_collection';
$this->_blockGroup = 'story';
$this->_headerText = Mage::helper('customer')->__('Manager');
//Replace the first argument "add" by something else,
//or both your new button and the original add button
//won't be visible.
$this->_addButton('btnAdd', array(
'label' => Mage::helper('story')->__('Add Item'),
'onclick' => "setLocation('" . $this->getUrl('*/*/new', array('page_key' => 'collection')) . "')",
'class' => 'add'
));
//Moved parent's constructor here (not necessary I think)
parent::__construct();
//Remove original add button
$this->_removeButton('add');
}
此行删除原始添加按钮,只保留包含新操作的新按钮:
$this->_removeButton('add');
注意:请务必在致电:
后删除原始按钮parent::__construct();
或原始按钮将保留在网格中。
答案 1 :(得分:1)
public function __construct()
{
$this->_controller = 'adminhtml_collection';
$this->_blockGroup = 'story';
$this->_headerText = Mage::helper('customer')->__('Manager');
parent::__construct();
$this->_addButton('add', array(
'label' => Mage::helper('story')->__('Add Item'),
'onclick' => "setLocation('" . $this->getUrl('*/*/new', array('page_key' => 'collection')) . "')",
'class' => 'add'
));
}