Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to use FlashMessenger without redirect?

I wonder if its possible to use flash messenger without redirect? eg. After a failed login, I want to continue to display the form, no redirect required.

public function loginAction() {
  $form = new Application_Form_Login();

  ...

  if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getParams())) {
    $authAdapter = new Application_Auth_Adapter($form->getValue('username'), $form->getValue('password'));
    if ($this->auth->authenticate($authAdapter)->isValid()) {
      ...
    } else {
      // login failed
      $this->flashMessenger->addMessage('Login failed. You may have entered an invalid username and/or password. Try again');
    }
  }

  $this->view->form = $form;
}
like image 923
Jiew Meng Avatar asked Dec 23 '10 07:12

Jiew Meng


1 Answers

You can retrieve flash messages without redirect using $this->flashMessenger->getCurrentMessages(); Example:

$this->view->messages = array_merge(
    $this->_helper->flashMessenger->getMessages(),
    $this->_helper->flashMessenger->getCurrentMessages()
);
$this->_helper->flashMessenger->clearCurrentMessages();
like image 81
ischenkodv Avatar answered Nov 15 '22 11:11

ischenkodv