Skip to content

Instantly share code, notes, and snippets.

@treetop1500
Last active September 30, 2016 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save treetop1500/e2acf684001a41eceb74c0f34818240a to your computer and use it in GitHub Desktop.
Save treetop1500/e2acf684001a41eceb74c0f34818240a to your computer and use it in GitHub Desktop.
Flash Message
// controller delete action:
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
...
try {
$em->remove($entity);
$em->flush();
} catch(ForeignKeyConstraintViolationException $e) {
$this->addFlash('warning', 'This item is in use by related entities and cannot be deleted.');
}
// twig (Foundation 5):
{% for flash_message in app.session.flashBag.get('warning') %}
<div data-alert class="alert-box warning">
{{ flash_message|raw }}
<a href="#" class="close">&times;</a>
</div>
{% endfor %}
// twig (Foundation 6):
{% for flash_message in app.session.flashBag.get('warning') %}
<div class="callout warning" data-closable>
{{ flash_message|raw }}
<button class="close-button" aria-label="Dismiss alert" type="button" data-close>
<span aria-hidden="true">&times;</span>
</button>
</div>
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment