Flash Session weirdness

Hi there,

I've created the following partial:

{% if flashSession.getMessages()|length > 0 %}

  <div class="row">
    <div class="small-12 columns">

      {{ flashSession.output() }}

    </div>
  </div>

{% endif %}

If I leave the length test in, when it is true, my markup is output but flashSession.output() returns nothing. If I comment out the length test, when there are messages, flashSession.output() works as expected.

It seems like calling getMessages() to check the count removes the messages? Basically, I'm checking for existence of messages to avoid outputting extraneous markup when there is no need to.

Am I misunderstand something?

Many thanks.



5.6k

I guess that might just as well be the case.. I never worked with it this way, and the following is not documented in the API reference, but does this work: .getMessages(null, false) ?

Ref: http://phalcon.agent-j.ru/en/1.3.0/Phalcon/Flash/Session#getMessages-details

I guess the length check isn't necessary (an empty array gives false).

I also notice the has method.. Perhaps that's intended for what you're trying to accomplish?



23.9k

HI @renski - thanks for the link! I have never come across that API reference before. There is much more information in there than I have been seeing in the Docs section :)

I'll check this out further based on your suggestions and will report back with my progress. I appreciate your help.



9.9k

If i remember correctly, all partials are sanboxed, so you have to explicitly pass flashSession as a variable into your partial.

{{ partial("partials/footer", ['flashSession': flashSession ]) }}