我有一个带有两个标签的页面,一个搜索标签和一个带有数据库网格的标签。在用户编辑网格中的一个项目之后,我想将它们保留在网格选项卡上,而不是首先按顺序排列的表单选项卡。
有没有办法通过代码更改页面上的活动标签?
这是标签的代码:
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();
}
这是我的控制器中处理重定向的saveAction:
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('*/*/');
}
答案 0 :(得分:11)
为什么不
$this->_redirect('*/*/', array('active_tab' => 'list_untranslated'));
答案 1 :(得分:6)
是的,你可以通过更改'active'=>来实现_beforeToHtml()中的true / false属性 ...只需在saveAction()中传递参数或设置会话值...所以当页面被重定向时,如果设置了参数,则检查你的beforeToHtml(),你改变了'active'=>的顺序。 $ somevariable。
基本上这样做,
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();
}