1
votes

I'm writing a custom Helper class by extending Zend_Controller_Action_Helper_Abstract. Inside this Helper class I want to make use of FlashMessenger to show messages when needed. I want to discriminate warning, success, and error messages ( no, I'm not a racist ).

In a class which extends Zend_Controller_Action I do that something like this, see below.

$this->_helper->FlashMessenger(array('error' => 'An error occured'));

When writing a Helper class, which extends Zend_Controller_Action_Helper_Abstract you can get the Helpername by using the getActionController() and getHelper methods together. See below.

$this->getActionController()->getHelper('FlashMessenger');

I want to add the array('error' => 'An error occured') as an argument to the FlashMessenger helper inside the getHelper mehod. I was wondering, is it possible to add arguments to the FlashMessenger Helper through getHelper? If not, then how can you work around this?

1

1 Answers

1
votes

This link provides a solution:

So if anyone wants to set the flash messages from outside of the action controllers, then you should use something like this using Zend_Controller_Action_HelperBroker class and its static helper getStaticHelper.

$flashmessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');  
$flashmessenger->addMessage(array('error' => 'An error occured')); 

Since getHelper('FlashMessenger') returns an instance of Zend_Controller_Action_Helper_FlashMessenger, you should be able to do:

$this->getActionController()->getHelper('FlashMessenger')->addMessage(array('error' => 'An error occured'));