-1

I'm wondering why this does not have implementation in Symfony2 or Yii...

My thought is: I want to place ALL errors in flash under one INDEX = 'errors' or 'success', so that i can just render them using foreaches.

How flashes work now is:

(yii example) setFlash('error','error message') this sets flash for one message and if i do this setFlash('error','error message2') this will REPLACE last message. What if I have more then one error message? It's dynamical - i can't know all the indexes.

The same thing in Symfony2. I suspect this was done for a reason, but i don't know what it is. It seems to me it's far better to make indexes non-replacable, but deleteble.

lin
  • 17,956
  • 4
  • 59
  • 83
drakonli
  • 2,304
  • 23
  • 29

1 Answers1

2

The flash message implementation of Symfony2 supports multiple messages for the same key. If you look at the implementation you just have to use the following method of the FlashBag class:

/**
 * {@inheritdoc}
 */
public function add($type, $message)
{
    $this->flashes[$type][] = $message;
}
sebbo
  • 2,929
  • 2
  • 20
  • 37
  • 1
    Indeed you are right, my good man!:) And for "the right way" of retrieving flashes in twig i found this answer - http://stackoverflow.com/questions/8240110/flash-messages-in-symfony2-doesent-seem-to-work-in-my-twig-template. – drakonli Aug 31 '14 at 12:42