4

I am working Magento community edition 1.7 version.

I have a grid in admin panel. Now when I click on this URL it open a form with two tabs in left sidebar. When I click on second tab it show a grid in its right side.

Then I click on a row of this grid it opens a form on another page. In this form there is back button.

How can I change its URL to previous page?

4 Answers 4

9

Add your custom back button and remove default one in your Form Container class constructor.

$data = array(
        'label' =>  'Back',
        'onclick'   => 'setLocation(\'' . $this->getUrl('*/*/*') . '\')',
        'class'     =>  'back'
   );
$this->addButton ('my_back', $data, 0, 100,  'header'); 
...
parent::__construct();
...
$this->_removeButton('back');
6

Just need to override getBackUrl function:

class [Namespace]_[Module]_Block_Adminhtml_[CustomBlock] extends Mage_Adminhtml_Block_Widget_Form_Container
{

/** code **/

public function getBackUrl()
    {
        parent::getBackUrl();
        return $this->getUrl('[New URL]');
    }

/** code **/
}

Note: Tested in Magento ver. 1.9.1.0

2
  • I think it's not necessary to call parent method. Feb 2, 2016 at 6:04
  • 2
    Shouldn't this answer be the accepted one? It uses a specific method provided to handle this issue. The other answers advise taking an unnecessary path in recreating the back back altogether. Mar 24, 2016 at 13:51
2

simply override the default back button:

parent::__construct();

$data = array(
        'label' =>  'Back',
        'onclick'   => 'setLocation(\'' . $this->getUrl('*/*/*') . '\')',
        'class'     =>  'back'
   );
$this->addButton ('back', $data, 0, 100,  'header'); 

Notice the placement of parrent::__construct();

0

Here is simplest way to change url of back button.

protected function _construct()
{
    $this->_objectId = 'row_id';
    $this->_blockGroup = 'Namespace_Modulename';
    $this->_controller = 'adminhtml_grid';
    parent::_construct();
    if ($this->_isAllowedAction('Namespace_Modulename::add_row')) {
        $this->buttonList->update('save', 'label', __('Save'));
    } else {
        $this->buttonList->remove('save');
    }
    /**
     * Below line to change your back url of grid
     */
    $this->buttonList->update('back', 'onclick', 'setLocation(\'' . $this->getUrl('*/*/index') . '\')');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.