We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Flash message not working on "direct render"

Hi I have some problem with the flash message

When my form is invalid i add the error message on flash (Direct Flash) they are not display in view. Here is my controller

    $form = new SeriesForm();
          $formClass = '';
          $errorField = [];
          try {
              if ($this->request->isPost()) {
                  if ($form->isValid($this->request->getPost()) == false) {

                      foreach ($form->getMessages() as $message) {
                          $this->flash->error($message);
                      }
                      $errorField = $form->getErrorFiedsArray();

                  } else {
                      //Valid form, we create the series

                  }
              }
          } catch (Exception $e) {
              $this->flash->error($e->getMessage());
          }

          $this->view->errorField = $errorField;
          $this->view->formClass = $formClass;
          $this->view->form = $form;

and here the view where I display the flash

    <?php
    echo $this->flashSession->output();
    echo $this->flash->output();
    ?>

When I try with $this->flashSession->error($message); the message is shown, but in that case, without redirect, Flash\Direct should work, right ?

Here is my phalcon versions

    Versions:
      Phalcon DevTools Version: 3.2.5
      Phalcon Version: 3.2.2
      AdminLTE Version: 2.3.6
edited Nov '17

Direct messages are written to the current buffer, so they go to the view output:

// volt
{{ content() }}
// php
echo $this->getContent();


8.2k

Oh, so for Direct Flash, I need to change my flash->output() to getContent() ?

Seems a bit weird to me, but if that's it, thanks.