简体   繁体   中英

FlashMessenger with Zend - how can I send messages to another user?

I'm trying to use FlashMessenger to notify another user of an event. Does anyone know if this is possible?

Something like

$flashMessenger->addMessage( array('status'=> '', 'message'=> 'Hello!'), $user);

Quoting the manual page of the FlashMessenger :

The FlashMessenger helper allows you to pass messages that the user may need to see on the next request. To accomplish this, FlashMessenger uses Zend_Session_Namespace to store messages for future or next request retrieval .

So, the messages are stored in session -- and a session is attached to / corresponds to a user ; the current user, actually.

The session is not meant to store data that is shared between different users -- so I would say that this component cannot be used to notify other users of an event ; not natively, at least.


A possible solution would be :

  • when you detect there is a message that must go to other users, store it in database (some table with a foreign key pointing to the destination user, if the destination user is a connected-user ; some table storing the message, if it can be seen by anyone) .
  • on each page, you check in that DB table if the is a message that has to be displayed
  • if yes, you put it in the FlashMessenger, which will display it on next page load from the current user.

A bit tricky, and not as easy as you'd hope, I admit...

Another idea, instead of using a database, would be to use some Caching engine (like APC, memcached, ... see Zend_Cache , to avoid hitting the DB.

Have fun !

Other option would be to implemment your own session handling and store it in DB (along with username). You can then access it and alter it in any way. We've implemented this when we needed to get past some crazy restrictions (one day limited session lifetime) of hosted enviroment's session setup. It works really good and offers much more possibilities over the default implementation (like sign out all users if some specific user signs in - superadmin for example or signout user if his password is changed in admin section, etc.).

But I guess this is a bit overkill for your purposes. And Pascal's way would be good enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM