2

我想要的是更改“添加新”按钮的操作

 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”更改为任何其他..请帮助

4

2 回答 2

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();

否则原始按钮将保留在网格中。

于 2013-05-13T17:02:13.797 回答
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'
    ));

}
于 2013-05-08T09:53:48.923 回答