我想要的是更改“添加新”按钮的操作
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”更改为任何其他..请帮助
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');
}
此行删除了原来的 add 按钮,只留下包含新操作的新按钮:
$this->_removeButton('add');
注意:调用后一定要删除原来的按钮:
parent::__construct();
否则原始按钮将保留在网格中。
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'
));
}