zend-expressive-flash icon indicating copy to clipboard operation
zend-expressive-flash copied to clipboard

Divide message key further

Open mano87 opened this issue 7 years ago • 2 comments

Currently, the key of the message is probably mainly used for the corresponding category "warning, info, danger, success". However, if you now have two forms in the page, the evaluation of this information and the output is a bit tricky. It would be nice if you can add the corresponding form name in addition to the key.

currently:

$flashMessages->flash('danger', 'You need to supply your email address');

suggestion:

$flashMessages->flash('danger', 'You need to supply your email address', 'form-name'); // OR
$flashMessages->flash('form-name:danger', 'You need to supply your email address');

$flashMessages->getFlashByForm('form-name');

What do you all mean?

mano87 avatar Aug 17 '18 07:08 mano87

I have been thinking about this as well and currently use it something like $flashMessages->flash('form-name:danger', 'message');.

$flashMessages->getFlashByForm('form-name');

I wouldn't call it getFlashByForm. I rather would like to see something like getFlashByNamespace. It does the same but it's more general.

$flashMessages->flash('danger', 'You need to supply your email address', 'form-name');

This cannot happen without a BC break. The current signature is public function flash(string $key, $value, int $hops = 1) : void;. So you would have something like public function flash(string $key, $value, int $hops = 1, string $namespace = null) : void;.

However I think I rather see something like this: public function flash(string $namespace, $value, int $hops = 1, array options = null) : void;, where options can be anything. You can add your message level (error, danger, success), form name, field name or whatever you want. To make it even more powerful, a namespace could have multiple messages.

public function getMessagesForNamespace(string $namespace) : array;

geerteltink avatar Aug 17 '18 15:08 geerteltink

This repository has been closed and moved to mezzio/mezzio-flash; a new issue has been opened at https://github.com/mezzio/mezzio-flash/issues/1.

weierophinney avatar Dec 31 '19 20:12 weierophinney