PHPackages                             arturdoruch/flash-message-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. arturdoruch/flash-message-bundle

AbandonedArchivedSymfony-bundle[Mail &amp; Notifications](/categories/mail)

arturdoruch/flash-message-bundle
================================

Flash message notification bundle for Symfony.

1.0.2(9y ago)11.1k1MITPHP

Since Dec 30Pushed 9y ago1 watchersCompare

[ Source](https://github.com/arturdoruch/FlashMessageBundle)[ Packagist](https://packagist.org/packages/arturdoruch/flash-message-bundle)[ RSS](/packages/arturdoruch-flash-message-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

FlashMessageBundle
==================

[](#flashmessagebundle)

FlashMessageBundle allows in very convenient way sets or adds flash messages. It's helpful, when we want to give user some response information about controller action status. Flash message manager working with `Symfony\Component\HttpFoundation\Session\Flash\FlashBag` and every setting message is automatically translated by `Symfony\Component\Translation\Translation`.

Installation
------------

[](#installation)

Install bundle with composer

```
composer require arturdoruch/flash-message-bundle
```

Add bundle to application kernel.

```
// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new ArturDoruch\FlashMessageBundle\ArturDoruchFlashMessageBundle(),
    );
}
```

Configuration
-------------

[](#configuration)

This bundle configured under the `artur_doruch_flash_message` key in your application configuration.

\####*classes*

**type**: array **default**:

```
    success: success
    error: danger
    notice: warning

```

An array of key-value pairs, where key is a message type and value a css class name. This parameter allows to define string that can be used in template as CSS class name for stylize displaying messages.

```
// app/config/config.yml
artur_doruch_flash_message:
    classes:
        error: fail
        notice: notice
        custom: custom-class-name
```

To use this parameter in template call `ad_flash_messages_class_name(type)` function with message type as parameter. See `Resources/views/messages.html.twig` file.

Controller
----------

[](#controller)

Every message setting by service `ad_flash_message` is automatically translated by `Symfony\Component\Translation\Translation`.

To get flash message service.

```
public function indexAction()
{
    $flash = $this->get('ad_flash_message');
    ...
}
```

##### Set, add messages

[](#set-add-messages)

By default flash messages are translated with "messages" domain. Methods starting with name "add" or "set", adds or sets messages to `Symfony\Component\HttpFoundation\Session\Flash\FlashBag`, which next we can display in view template.

```
/**
 * Translates custom type message and sets it into session flash bag. Overrides previous message if was set.
 *
 * @param string      $type        Can be any string describing action status. For types: "success", "error", "notice"
 *                                 use dedicated methods "setSuccess", "setError", "setNotice".
 *
 * @param string|null $message     Message text. Given text is always translated by "Symfony\Component\Translation\Translation"
 *                                 with "message" domain as default (of course if exists any translations for given string).
 *                                 If $message is null then will be dynamically creates as "translationId" based
 *                                 on called controller action name in convention: "company_bundle_controller.action.$type".
 *                                 For example, if we call this method (and $message is null) in controller
 *                                 "App\DemoBundle\Controller\ProductController::createAction"
 *                                 then will be generated this "translationId" value: "app_demo_project.create.$type".
 *
 * @param array       $parameters  Parameters for translation message.
 * @param string|null $domain      Translation domain. As default is "messages".
 */
public function set($type, $message = null, array $parameters = array(), $domain = null) {}

/**
 * Adds and translates custom type flash message.
 */
public function add($type, $message = null, array $parameters = array(), $domain = null) {}
```

Difference between methods "set" and "add" is obvious. "add" adds new message into flashBag array collection, while "set" override existing array messages collection by new one.

##### Get messages

[](#get-messages)

Methods starting with name "get" only prepare message and returns it without adding to `Symfony\Component\HttpFoundation\Session\Flash\FlashBag`. It's useful if you want to return translated message. For example if you work with REST api or Ajax request.

```
/**
 * Gets custom type translated flash message.
 * This method not adds message into session flash bug.
 * Just creates, translates and returns it.
 */
public function get($type, $message = null, array $parameters = array(), $domain = null) {}
```

Instead sets $type by hand you can use these convenient methods.

```
/**
 * Available methods sets, adds or gets messages with concrete types: "Success", "Error", "Notice".
 */
public function setSuccess($message = null, array $parameters = array(), $domain = null) {}
public function setError($message = null, array $parameters = array(), $domain = null) {}
public function setNotice($message = null, array $parameters = array(), $domain = null) {}

public function addSuccess($message = null, array $parameters = array(), $domain = null) {}
public function adsError($message = null, array $parameters = array(), $domain = null) {}
public function addNotice($message = null, array $parameters = array(), $domain = null) {}

public function getSuccess($message = null, array $parameters = array(), $domain = null) {}
public function getError($message = null, array $parameters = array(), $domain = null) {}
public function getNotice($message = null, array $parameters = array(), $domain = null) {}
```

#### Add or get messages for CRUD actions.

[](#add-or-get-messages-for-crud-actions)

FlashMessageBundle provides methods for the easy way setting flash messages, when we're doing repetitive CRUD operations. Messages for CRUD action are translated with "crudMessages" domain. See `Resources/translations/crudMessages.en.yml` file in this bundle.

```
/**
 * Adds and translates flash message for CRUD action.
 * Generates "translationId" based on given parameters values and/or
 * dynamically generated based on $entity value and called controller name.
 * Generated "translationId" has format "crud.action.type".
 * All CRUD messages are translated with "crudMessages" domain.
 * See 'Resources/translations/crudMessages.en.yml'.
 *
 * @param string $type         Can be any string describing action status. For types: "success", "error", "notice"
 *                             use dedicated methods "addCrudSuccess", "addCrudError", "addCrudNotice".
 *
 * @param string $entity       Persistence entity object or entity name. Is used as parameter %entity%
 *                             in translation files.
 *                             For more clarify see "Resources/translations/crudMessages.en.yml" file.
 *
 * @param null|string $item    Single entity object name. Is used as parameter %item% in translation files.
 *                             For more clarify see "Resources/translations/crudMessages.en.yml" file.
 *
 *                             If $item is null and $entity is object then
 *                             will attempt to call methods getName() on $entity object "$entity->getName()".
 *                             If method exists then $item will be filled by the returned value.
 *
 * @param null|string $action  This parameter is used for generate "translationId".
 *                             If null then $action is generated based on called controller action name.
 *                             For example if called controller is     "App\DemoBundle\Controller\ProductController::createAction"
 *                             $action will be "create".
 */
public function addCrud($type, $entity, $item = null, $action = null) {}

/**
 * Gets custom type translated flash message for CRUD action.
 * This method not adds message into session flash bug.
 * Just creates, translates and returns it.
 */
public function getCrud($type, $entity, $item = null, $action = null) {}

/**
 * Other available methods adds or gets CRUD messages with concrete types: "Success", "Error", "Notice".
 */
public function addCrudSuccess($entity, $item = null, $action = null) {}
public function addCrudNotice($entity, $item = null, $action = null) {}
public function addCrudError($entity, $item = null, $action = null) {}

public function getCrudSuccess($entity, $item = null, $action = null) {}
public function getCrudNotice($entity, $item = null, $action = null) {}
public function getCrudError($entity, $item = null, $action = null) {}
```

### Example usage

[](#example-usage)

```
public function indexAction()
{
    ...
    $flash = $this->get('ad_flash_message');

    // Set flash messages
    $flash->setSuccess();
    $flash->setError();
    $flash->set('customType', 'Some flash message');

    // Add another message for "success" type array collection.
    $flash->addSuccess('Another success message');
}

public function sendEmailAction()
{
    ...
    $flash = $this->get('ad_flash_message');

    // Set flash messages with custom domain
    // Email was successfully send.
    $parameters = array(
        '%user%' => 'John Doe'
    );
    $flash->setSuccess(null, $parameters, 'emailMessages');

    // Failure email sending.
    $flash->setError(null, array(), 'emailMessages');

    // Get flash message
    return new Response($flash->getSuccess(null, $parameters, 'emailMessages'));
}
```

\#####CRUD example.

```
public function updateAction(Product $product, Request $request)
{
    ...
    $product->setName('Framework');

    // Create and valid form. If form is valid save entity and set flash message.

    $flash = $this->get('ad_flash_message');
    // Message will be "Product Framework has been updated."
    $flash->addCrudSuccess($product);

    // For this message in translation file "crudMessages" must be defined
    // new key 'crud.customaction.success'.
    $flash->addCrudSuccess('Product2', 'Bundle', 'customAction');
    // Add Crud message with custom type.
    $flash->add('customType', 'Product', 'Github');

    // Get message
    $updateSuccessMsg = $flash->getCrudSuccess($product);
}
```

\##View

\###Usage

For displaying flash messages just write this line of code into your base template file or wherever you want.

```
    {{ ad_flash_messages() }}
```

\#####Optional

```
    {{ ad_flash_messages_class_name(type) }}
```

This function returns CSS class name related to given message type parameter. Helps to customize displaying messages by CSS style. See how [configuration CSS classes names.](#classes)

Of course you can customize whole messages template by overriding `Resources/views/messages.html.twig` file. To do this put template file into `app/Resources/ArturDoruchFlashMessageBundle/views/messages.html.twig` location in your Symfony app.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~409 days

Total

3

Last Release

3336d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5af341236bd5f7de04934e7b63ab71d774df81f5409e7fafd19ede18c0cd6c2a?d=identicon)[arturdoruch](/maintainers/arturdoruch)

---

Top Contributors

[![arturdoruch](https://avatars.githubusercontent.com/u/6686928?v=4)](https://github.com/arturdoruch "arturdoruch (12 commits)")

---

Tags

symfonybundlenotificationflash message

### Embed Badge

![Health badge](/badges/arturdoruch-flash-message-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/arturdoruch-flash-message-bundle/health.svg)](https://phpackages.com/packages/arturdoruch-flash-message-bundle)
```

###  Alternatives

[stephpy/timeline-bundle

Symfony2 bundle to make timeline

192368.4k4](/packages/stephpy-timeline-bundle)[mcfedr/awspushbundle

A set of services to simplify using Aws to send push notifications

40378.6k1](/packages/mcfedr-awspushbundle)[secit-pl/imap-bundle

PHP-IMAP Symfony integration.

711.5M2](/packages/secit-pl-imap-bundle)[ras/flash-alert-bundle

FlashAlertBundle provides a simplified way to handle (add/display) Symfony flash messages. Client side scripts are written in pure JavaScript.

2423.3k](/packages/ras-flash-alert-bundle)[scullwm/mailhookbundle

A bundle to catch API webhook from differents mail service

4020.5k](/packages/scullwm-mailhookbundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
