Magento tab change/redirect

纵饮孤独 提交于 2020-01-13 11:06:55

问题


I have a page with two tabs, a search-tab and a tab with a grid of the database. After the user edits one of the items in the grid, I'd like to keep them on the grid tab, rather than the form tab which is first in order.

Is there a way to change the active tab on a page via code?

This is the code for the tabs:

protected function _beforeToHtml()
{
    $this->addTab('search_string', array(
        'label'     => Mage::helper('advancedtranslate')->__('Find a string'),
        'title'     => Mage::helper('advancedtranslate')->__('Find a string'),
        'content'   => $this->getLayout()->createBlock("advancedtranslate/adminhtml_advancedtranslate")->toHtml(),
        'active'    => true
    ));

    $this->addTab('list_untranslated', array(
        'label'     => Mage::helper('advancedtranslate')->__('Untranslated strings'),
        'title'     => Mage::helper('advancedtranslate')->__('Untranslated strings'),
        'content'   => $this->getLayout()->createBlock("advancedtranslate/adminhtml_grid")->toHtml(),
        'active'    => false
    ));

    return parent::_beforeToHtml();
}  

And this is the saveAction in my controller that handles the redirect:

public function saveAction(){
    //write data away to core_translate table
    $resource   = Mage::getResourceModel('core/translate_string');

    $request              = $this->getRequest();
    $translate_id         = $request->getParam('id');
    $original             = $request->getParam('original_translation');
    $custom               = $request->getParam('string');
    $locale               = $request->getParam('locale');
    $storeId              = $request->getParam('storeid');
    $storeViewSpecific    = $request->getParam('storeview_specific');

    if($storeId != 0 && $storeViewSpecific != 1){
        $storeId = 0;
    }

    $resource->saveTranslate($original, $custom, $locale, $storeId);

    //delete record from phpro table
    $advancedTranslateRecord = Mage::getModel('advancedtranslate/advancedtranslate');

    $advancedTranslateRecord->setId($translate_id)
                            ->delete();

    //clear the cache
    Mage::app()->getCache()->clean();

    Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')
                                           ->__('Translation was saved.'));
    $this->_redirect('*/*/');
}

回答1:


Yes you can do so by changing the 'active' => true / false attribute in your _beforeToHtml() ... simply pass a parameter or set a session value in your saveAction()... so when the page gets redirected you check in your beforeToHtml() if the parameter is set you change the order of 'active' => $somevariable.

So basically do,

protected function _beforeToHtml()
{
        $active = true;
        if(Mage::getSingleton('admin/session')->getData('ActiveTab')) {
            $active = false;
        }
    $this->addTab('search_string', array(
    'label'     => Mage::helper('advancedtranslate')->__('Find a string'),
    'title'     => Mage::helper('advancedtranslate')->__('Find a string'),
    'content'   => $this->getLayout()->createBlock("advancedtranslate/adminhtml_advancedtranslate")->toHtml(),
    'active'    => $active
    ));

    $this->addTab('list_untranslated', array(
    'label'     => Mage::helper('advancedtranslate')->__('Untranslated strings'),
    'title'     => Mage::helper('advancedtranslate')->__('Untranslated strings'),
    'content'   => $this->getLayout()->createBlock("advancedtranslate/adminhtml_grid")->toHtml(),
    'active'    => !$active
    ));

    return parent::_beforeToHtml();
}



回答2:


Why not just

$this->_redirect('*/*/', array('active_tab' => 'list_untranslated'));


来源:https://stackoverflow.com/questions/7671358/magento-tab-change-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!