Wouldn't it be better to provide a method to retrieve the messages regardless of which page load it is in so that the flashMessanger could be the generic message container for either case?

For example, if I do:

$this->_flashMessenger->addMessage('My Message');
$messages = $this->_flashMessenger->getMessages();

I would assume that $message should contain 'My Message' since I just added it in the previous line, but it doesn't. The addMessage() method stores the message in the session, while getMessage() retrieves from the $_message property of the object. The $_message property is populated only from the previous request but not updated when new messages are added.

In some cases the part of the application that needs to indicate a message won't know yet if the page will re-direct or not at the end so it seems silly to use two different models for the basically the same purpose (message storage). Could the flashMessanger provide a getAllMessages() method that would remove like messages from the session if they're retrieved on the same call so you get all message without repeating them in the next request?

I guess this could be accomplished by manually merging getMessages() and getCurrentMessages() but then you have to manually clear the current messages too which is something else to remember. It would be nice to have something like this in the FlashMessenger:

function getAllMessages( $clear = true ) {
$all = array_merge( $this->getMessages(), $this- >getCurrentMessages() );
        if ( true === $clear) {
                $this->clearMessages();
        }
        return $all;
}

- Jeff


On 3-Jun-08, at 10:22 AM, Jake McGraw wrote:

FlashMessenger is meant for displaying messages only after receiving a
second request, like a redirect:

FIRST REQUEST
Client to Server - POST form values
Server - Process form values
Server - Form values will cause a redirect, record all messages FlashMessenger
Server to Client - Send redirect

SECOND REQUEST
Client to Server - GET redirect page
Server - Check FlashMessenger queue for messages
Server to Client - Print out messages

In order to solve your problem, record messages to an internal message
queue (say an array on Zend_Registry) when you aren't redirecting,
otherwise use FlashMessenger.

- jake

On Tue, Jun 3, 2008 at 10:11 AM, Jeffrey Sambells
<[EMAIL PROTECTED]> wrote:
I think the issue is around adding to the flash messenger and then
retrieving the message at the end of the same request (no refresh). I'm having a similar issue where we use the flash messenger to store messages
and then try to retrieve them during the same request. Sometimes the
application needs to re-direct and sometimes not so the flash messenger seemed the appropriate place to store them but often they don't show up until the following page load. I haven't had time to loot into it though.

- Jeff


On 3-Jun-08, at 9:56 AM, Bart McLeod wrote:

If you submit the form and validate it, your post data will still be in the form, while the page has been refreshed (there has been a round trip to
the server upon form submission).

I did never use flashmessenger, but I do not see why it would not display its message when the user submits the form and thus refreshes the page?

Bart

Vincent schreef:

Hi,

In my project, the user now and then has to submit a form. Sometimes, there is an error with processing this form (e.g. the data couldn't be
inserted into the database).

To communicate this to the user, I use the FlashMessenger action helper. However, the FlashMessenger won't display its messages until the next page load, which means I'll either have to refresh the page and lose the POST data, or preserve the POST data so I can populate the form with whatever the
user just submitted, but lose the error message.

What would be the recommended way to have both?

Thanks,
--
Vincent



Reply via email to