Magento : Flash / Session Notification Messages
Magento offers an inbuilt flash message class and functions to display success, error, warning and notice messages.
Default Magento installation has a bunch of system / flash / notification messages that get outputted to the browser. You can think of this as a notification system functionality of Magento.
It is something every theme and/or extension developer should know about. This notification system uses exactly four different messages or message types. These are: error, warning, notice, success.
In Magento, there are different types of message:-
1. Notice
Mage::getSingleton(‘core/session’)->addNotice(‘Notice message’);
2. Success
Mage::getSingleton(‘core/session’)->addSuccess(‘Success message’);
3. Error
Mage::getSingleton(‘core/session’)->addError(‘Error message’);
Warning (admin only)
Mage::getSingleton(‘adminhtml/session’)->addWarning(‘Warning message’);
In your custom module or anywhere in phtml code, you can add the above code and Magento will display the message on the next page that you load.
The frontend and backend messages are handled by different block classes. The code you are editing is only used in the frontend of Magento. If you wish to customise the Backend messages you will need to edit/overload a different class, namely Mage_Adminhtml_Block_Messages (which is located in /app/code/core/Mage/Adminhtml/Block/Messages.php).
Messages are stored on a session model. Default Magento installation comes with the following session models.
‘core/session’
‘adminhtml/session’
‘customer/session’
‘catalog/session’
‘catalogsearch/session’
‘checkout/session’
‘connect/session’
‘install/session’
‘tag/session’
‘wishlist/session’
Each of these session models is capable of accepting those four types of messages by simple ->add{MessageType} method call like shown on the example below.
Mage::getSingleton(‘core/session’)->addError(‘Message here’);
Mage::getSingleton(‘core/session’)->addWarning(‘Message here’);
Mage::getSingleton(‘core/session’)->addNotice(‘Message here’);
Mage::getSingleton(‘core/session’)->addSuccess(‘Message here’);
Once you add a message to the session model, it will get rendered on the front-end on the next page that gets loaded.
Hello there, simply changed into aware of your weblog through Google, and found that it is truly informative.
I’m going to watch out for brussels. I’ll appreciate should