Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

show succes / error message in custom controller
 
R.Verheij
Jr. Member
 
Avatar
Total Posts:  16
Joined:  2008-04-08
Amsterdam, Netherlands
 

Hi,

I created a custom controller that shows an overview of youtube movies about a product.
Users are able to add new movies and once the movie is added I want to show a succes message.
Looking at other controllers I thought this might work:

class Mage_Catalog_Product_VideoController extends Mage_Core_Controller_Front_Action
 {
   
    
public function addAction()
    
{
       
..... 
       
Mage::getSingleton('catalog/session')->addSuccess($this->__('Your video was successfully added'));
       .....
       
$this->loadLayout();
       
$this->_initLayoutMessages('catalog/session');
       
$this->renderLayout();
    
}

But the message is only shown once I go to a catalog page…
Does anyone know how it should be done?

 
Magento Community Magento Community
Magento Community
Magento Community
 
gamelodge
Sr. Member
 
Avatar
Total Posts:  89
Joined:  2007-08-31
Brisbane, Qld, Australia
 

Did you manage to figure this one out, I am trying to do the same, but nothing i do get the message to display on frontend

 
Magento Community Magento Community
Magento Community
Magento Community
 
Anton Makarenko
Magento Team
 
Avatar
Total Posts:  184
Joined:  2008-05-13
Los Angeles, CA
 

Please make sure to call this in template:

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
If not helping, try to add messages not to ‘catalog/session’, but to ‘core/session’.
 
Magento Community Magento Community
Magento Community
Magento Community
 
gamelodge
Sr. Member
 
Avatar
Total Posts:  89
Joined:  2007-08-31
Brisbane, Qld, Australia
 

Yes I have that in my template.

and my controller has this:

public function checkAction(){

        $this
->loadLayout();    
        
$session $this->_getSession();
        
$this->_initLayoutMessages('core/session');

        if (
$this->getRequest()->isPost()) {
            $suburb 
$this->getRequest()->getPost('suburb');
            if (!empty(
$suburb)) {
                $session
->addError($this->__('Well Done'));
            
else {
                $session
->addError($this->__('Login and password are required'));
            
}
        }
        
        $this
->_redirect('*/*/index');
        
}
This is just Test data to get the error to show

But i just cannot get the Error to show on the template.... is it because of the redirect?
i dont reallu know what ‘initLayoutMessages’ does either

 
Magento Community Magento Community
Magento Community
Magento Community
 
Anton Makarenko
Magento Team
 
Avatar
Total Posts:  184
Joined:  2008-05-13
Los Angeles, CA
 

What if add $this->setFlag(’’, self::FLAG_NO_DISPATCH, true); before redirecting? I used this to add messages inside preDispatch().

 
Magento Community Magento Community
Magento Community
Magento Community
 
cweiske
Jr. Member
 
Total Posts:  6
Joined:  2008-04-13
 

I had the same problem when using the 1column.phtml template (via setTemplate). 1column.phtml does not display any errors.
Beside that, we had

<block type="core/messages" name="global_messages" as="global_messages"/>
            <
block type="core/messages" name="messages" as="messages"/>
in our page.xml which caused the message list to be cleared.

Solution for me was to use the following in my 1column-derived template:

<?php echo $this->getBlockHtml('global_messages'?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Jefferson Luís
Jr. Member
 
Avatar
Total Posts:  13
Joined:  2010-03-24
Brasil - Blumenau/SC
 

My solution:

$msg $this->_getSession()->getMessages(true);              

                
$this->loadLayout();
                
$this->getLayout()->getMessagesBlock()->addMessages($msg);             
                
$this->_initLayoutMessages('core/session');
                
$this->renderLayout();
 
Magento Community Magento Community
Magento Community
Magento Community
 
kiatng
Enthusiast
 
Total Posts:  875
Joined:  2008-09-03
Kuala Lumpur, Malaysia
 

@Jefferson That works great!

 
Magento Community Magento Community
Magento Community
Magento Community
 
davidseloo
Jr. Member
 
Total Posts:  3
Joined:  2011-12-28
 
Anton Makarenko - 31 July 2008 12:42 AM

Please make sure to call this in template:

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
If not helping, try to add messages not to ‘catalog/session’, but to ‘core/session’.

Thanks Anton Makarenko,

My problem was change ‘customer/session’ to ‘core/session’

Regards,
David

 
Magento Community Magento Community
Magento Community
Magento Community
 
christinavick
Guru
 
Total Posts:  355
Joined:  2013-11-13
 

Hi,

Have a look this thread http://stackoverflow.com/questions/10795483/how-to-add-custom-error-message-in-magento

Hope this will help you!!

Thanks

iLoveMage

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top