Magento add notification, success, and error messages

Assume you have a controller that uses the app/design/frontend/base/default/template/page/1column.phtml layout. You can add success or error notification messages in the controller action function like these
[code language=”php”]
Mage::getSingleton("core/session")->addNotice("Some notification message");
Mage::getSingleton("core/session")->addSuccess("Some action success message");
Mage::getSingleton("core/session")->addError("Some error message");
[/code]

If you open up the 1column.phtml or 2columns-left.phtml or 2columns-right.phtml or 3columns.phtml, you will find these messages are being included by this line of code.
[code language=”php”]
<?php echo $this->getChildHtml(‘global_messages’); ?>
[/code]

If you open up the app/design/frontend/base/default/layout/page.xml, you will find that the template global_messages is defined by this line of xml code.
[code language=”xml”]
<block type="core/messages" name="global_messages" as="global_messages"/>
[/code]

Search within Codexpedia

Custom Search

Search the entire web

Custom Search