-- Julian Davchev <[EMAIL PROTECTED]> wrote
(on Friday, 22 June 2007, 03:23 PM +0300):
> We all know about the problem with refreshing page , when it says there
> is post data...do you want to resubmit etc.
> How could that be avoided with ZF.
> 
> 
> Only way I know to  browser not show this message about posted data...is
> to redirect. Problem with redirecting is
> how do you transfer/show the success/error message - I am thinking to
> write messages in sessions but would be kind of weird I think.
> If I use just $this->_forward()    I can  messages in normal
> workflow...but post data is kept in browser.
> 
> Other option I see is using Ajax solution, but then again, I want the
> system to work with/wihtout ajax enabled(javascript).
> 
> How do you solve this issue, any good practices?

Use the FlashMessenger action helper in conjunction with the Redirector.
Usage is very simple. In your action that handles the form, do something
like:

    // Add a message
    $this->_helper->flashMessenger->addMessage('success!');

    // Redirect
    // Provide the name of the next action; when used like this, it acts
    // like _forward(), but issues a redirect:
    $this->_helper->redirector('next'); // 

Then, in the action to which you redirected:

    $flash = $this->_helper->getHelper('flashMessenger');
    if ($flash->hasMessages()) {
        $this->view->messages = $flash->getMessages();
    }

Note that the assumption is that there may be multiple messages, so an
array of messages will be returned; simply grab the first one if you
know there will only ever be one:

    <?= $this->escape($this->messages[0]) ?>

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to