Magento 1.9 core seesion message vanishing on home page

Viewed 69

I'm setting a message to core session from controller and redirect to home page Ex -

$session = Mage::getSingleton('core/session');
$session->addError('This is test message');
$this->_redirect('/');

But it's not display on home page, i checked xml files and other blocks too but can't find any clue. When i debug the message on home page phtml file it shows like this

 $messages=Mage::getSingleton("core/session")->getMessages();
    var_dump($messages);

object(Mage_Core_Model_Message_Collection)#77 (2) { 
["_messages":protected]=> array(0) { } ["_lastAddedMessage":protected]=> object(Mage_Core_Model_Message_Error)#76 (6) { 
["_type":protected]=> string(5) "error" ["_code":protected]=> string(34) "This is test message" ["_class":protected]=> string(0) "" ["_method":protected]=> string(0) "" 
["_identifier":protected]=> NULL ["_isSticky":protected]=> bool(false) } }

Anyone know how to fix this issue, Thank You

1 Answers

//A Success Message

Mage::getSingleton('core/session')->addSuccess("Some success message");

//A Error Message

Mage::getSingleton('core/session')->addError("Some error message");

//A Info Message (See link below)

Mage::getSingleton('core/session')->addNotice("This is just a FYI message...");

//These lines are required to get it to work

session_write_close(); //THIS LINE IS VERY IMPORTANT! $this->_redirect('module/controller/action');

// or

$url = 'path/to/your/page'; $this->_redirectUrl($url);

This will work in a controller, but if you're trying to redirect after output has already been sent, then you can only do that through javascript:

<script language=”javascript” type=”text/javascript”>
window.location.href=”module/controller/action/getparam1/value1/etc"";
</script> 
Related