KnpLabs/KnpRadBundle — pull request #33 by Herzult (2012-12-05 09:03:03+00:00)
Title: Flash messages

This PR tries to normalize the way we handle flash messages. It supports placeholders in messages, translation & pluralization.

The base controller has been updated to use instances of `Knp\RadBundle\Flash\Message` that are suitable for rendering through the `Knp\RadBundle\Flash\MessageRenderer`.

To create a flash message from a controller:

```php
addFlash('success', 'It works!');

// with some parameters
$this->addFlash('success', 'Hello {{ name }}!', array(
'{{ name }}' => $name
));

// with pluralization
$this->addFlash('success', 'An apple added.|{{ count }} apples added.', array(), $numApples);
}
```

From a twig template, you can render the flashes using the `flashes` tag:

```twig
{# basic exemple #}
{% flashes %}

{{ message }}

{% endflashes %}

{# specifying one type #}
{% flashes "success" %}

{{ message }}

{% endflashes %}

{# specifying an array of types #}
{% flashes ["success", "failure"] %}

{{ message }}

{% endflashes %}
```

By default, all the messages are translated using the `messages` catalog. But you can configure it:

```yaml
knp_rad:
flashes:
trans_catalog: flashes
```

or specify it in the `flashes` tag:

```twig
{% flashes ["success", "failure"] using catalog "flashes" %}

{{ message }}

{% endflashes %}
```