You can simply pass the whole FlashMessenger object to the ViewModel. In my application, I do this by always constructing ViewModels through a createViewModel method in my base controller which sets up the FlashMessenger association:
http://vufind.git.sourceforge.net/git/gitweb.cgi?p=vufind/vufind;a=blob;f=module/VuFind/src/VuFind/Controller/AbstractBase.php;h=672473a3df9e9bd25844ada523c03730f38399c5;hb=HEAD ...and then I have a custom View Helper which pulls data out of the FlashMessenger, displays it appropriately and clears the messages: http://vufind.git.sourceforge.net/git/gitweb.cgi?p=vufind/vufind;a=blob;f=module/VuFind/src/VuFind/Theme/Root/Helper/Flashmessages.php;h=7f62451dc735ddaaad1be1ffd9c501a2466d4910;hb=HEAD This allows me to display messages consistently on all screens without having to think too hard about it. I use namespaces that correspond with <div> classes so I can assign messages to different priorities -- hence all the looping in my helper. It's entirely possible that this solution can be improved -- in particular, it would be nice to avoid the need for always calling the createViewModel method. I'm open to suggestions... but as it stands, it works well enough for my needs. - Demian ________________________________________ From: Ralf Eggert [[email protected]] Sent: Friday, August 24, 2012 5:01 AM To: Zend Framework General Subject: [fw-general] ZF2: Access FlashMessenger from view helper Hi, Is it possible to access the FlashMessenger from a view helper in ZF2? I want to write a view helper that checks the FlashMessenger for any messages and outputs them if any exist. Regards, Ralf -- List: [email protected] Info: http://framework.zend.com/archives Unsubscribe: [email protected] -- List: [email protected] Info: http://framework.zend.com/archives Unsubscribe: [email protected]
