简体   繁体   English

如何通过转换适配器在导入过程中显示通知或成功消息?

[英]How to display notice or success message during the import by Convert Adapter?

How to display notice or success message during the import by the Convert Adapter ? 如何在转换适配器导入期间显示通知或成功消息?

I can only display error by 我只能显示错误

Mage::throwException($message) 法师:: throwException($消息)

. Class responsible for this is Mage_Adminhtml_Block_System_Convert_Profile_Run . 负责这个的类是Mage_Adminhtml_Block_System_Convert_Profile_Run

Magento actually have some kind a session message stack. Magento实际上有一些会话消息堆栈。 (Something quite similar to the message bags you can find, for example on Symphony). (与您可以找到的消息包非常相似,例如在Symphony上)。

Those are quite easy to use, just get the session associated to the area you are in and use on of the functions addError , addWarning , addNotice or addSuccess . 这些都是很容易使用,只得到关联到你是在和功能使用方面的会议addErroraddWarningaddNoticeaddSuccess

Since you are on the data flow module, the session you are looking to is dataflow/session . 由于您在数据流模块上,因此您要查找的会话是dataflow/session Take care to get this model via a singleton otherwise, you will end up with odd multiple sessions. 小心通过单例获得此模型,否则最终会出现奇数多个会话。

Mage::getSingleton('dataflow/session')->addSuccess($this->__('This will add a success message'));

The other are : 另一个是:

Mage::getSingleton('dataflow/session')->addNotice($this->__('This a notice'));
Mage::getSingleton('dataflow/session')->addWarning($this->__('That a warning'));
Mage::getSingleton('dataflow/session')->addError($this->__('And finally an error'));

And the reason you actually get an error message when you throw an exception, is because somewhere on Magento core, there is a 你抛出异常时实际得到错误消息的原因是因为在Magento核心的某处,有一个

try {
    // the code or class instantiation on which you throw your exception happens here
} catch (Mage_Core_Exception $e) {
    Mage::getSingleton('dataflow/session')->addError($e->getMessage());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM