Onman, on 13 February 2010 - 05:41 AM, said:
What you're probably looking for is the user 'flash' functionality.
Look in the manual for setFlash(), getFlash() and hasFlash().
Thanks, Onman! That is what I was looking for...or at least the beginning of what I need.
Maybe this wouldn't be useful in all cases, but I am currently working on an admin-type system where users log in and have access to manage data and run reports, etc. In this context, I am frequently sending messages back to the user, sometimes in relation to a model-based form, but often in relation to other activities that they perform. What I now need to create -- unless this is already out there as well -- is a widget (similar to the CHtml::error method) that encapsulates this get/setFlash functionality that I would include in all of my views. The widget would then check to see if any flash messages have been set, then output them already html formatted, just like CHtml::error.
The main problem I see with creating such a widget is that the getFlash method requires that you know the key of the message. There is no "getAllFlash()" method that would return an array of messages. Therefore, the CWebUser class would first have to be extended to provide the desired functionality. Then, in each view where it exists, the flashMessage widget could see if any messages exist, then loop through them and output each one. It would also be nice if you could set a message "type" when using setFlash, like message, notice, warning, error. Then, depending on the type that was set for the message the widget would apply a different style (css class) to the message on output.
Anyone else feel that this would be useful? I'll probably end up creating this for my own purposes, but if I'm not the only one who needs this sort of thing maybe I'll try to package it up. Again, the main issue is the lack of a getAllFlash method in the CWebUser class. I can make the output widget as a stand-alone entity, but if we also have to extend the base CWebUSer class then its not quite as convenient.
Anyone feel free to chime in with thoughts, suggestions, alternatives, or constructive criticism. Thanks!