Change / redirect Magento tab

I have a page with two tabs, a search tab and a tab with a database grid. After the user edits one of the elements in the grid, I would like to save them on the grid tab, and not in the form tab, which is primarily ordered.

Is there a way to change the active tab on a page using 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 saveAction in my controller that handles the redirection:

 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('*/*/'); } 
+4
source share
2 answers

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

So basically

 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(); } 
+6
source

Why not just

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

All Articles