Zend Framework: Flash Messenger, add a message from the model

Any idea on how best to add a message for the flash messenger from the model?

Since FlashMessenger is an action helper, this seems impossible, so the obvious solution is to create an internal message object in the model and return it to the controller, from where you can use addMessage (). But if you want to return something else, it will fall.

Another idea is an extra namespace for these internal messages, which is then merged with the Flash Messenger namespace messages in the output?

Anyone have any thoughts or experiences? Greetings.

+4
source share
2 answers

You can extract FlashMessenger from your model as follows:

$messenger = Zend_Controller_Action_HelperBroker::getStaticHelper('flashMessenger'); $messenger->addMessage('test message'); 
+7
source

Both routes sound correct.

One idea would be to add an $ message array to your model, which the action helper can access to retrieve messages. Thus, you can immediately return multiple messages at once.

Another option is to use the Theme / Observer template. Let your models implement the Subject interface and when you need to display messages, notify observers, for example. Flash messenger (for which you will need to implement the Observer interface).

+3
source

Source: https://habr.com/ru/post/1304165/


All Articles