php - Symfony 2.4 app.session.flashbag.all() returns empty value -
I have trouble using Flashbag messages. My case is quite simple:
My code
& Lt; Form action = "{{path ('form_url_save', {'id': id})}}" method = "POST" & gt; {{Form_widget (form)}} & lt; / Form & gt;
Save the data form through an administrator:
# src / namespace / mybundle / controller / entitycontroller PHP Public Function Save Action (Request $ request, unit $ entity = zero) {try {if (! $ Entity) {$ entity = new entity (); } $ Form = $ this- & gt; CreateForm (new EntityType ($ unit); If ($ request-> getMethod () == 'POST') {$ form-> Submit ($ request); If ($ form-> isValid ()) {// unit manager $ em = $ this- & gt; GetDoctrine () - & gt; GetManager (); // static data $ em- & gt; Continue ($ form-> getData ()); // savings process $ em-> Flush (); // Add FlashBag message $ this-> Receive ('session') - & gt; GetFlashBag () - & gt; Add ('success', 'backup was done successfully')); } And (new) exceptions ($ form-> getErrorsAsString ()); }}} Hold (\ Exceptions $ E) {$ this-> Receive ('session') - & gt; GetFlashBag () - & gt; Addition ('error', $ e-> getMessage ()); } $$ Return- & gt; Redirect ('home_page_url'); } Display a successful message in front of:
# app / resource / view / front.html.twig & lt ; Html & gt; & Lt; Top & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Div class = "main" & gt; {% Set flashbag = app.session.flashbag.all%} {% if the flashbag is not empty%} & lt; Div class = "messages-container" & gt; {% Type, FlashBag%} in message {% message in message%} for & lt; Div class = "alert alert - {{type}}" & gt; {{Message}} & lt; / Div & gt; {% Endfor%} {% endfor%} & lt; / Div & gt; {% Endif%} & lt; Div class = "content" & gt; // My content & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt; How is my theme organized? app / resources / view / front.html.twig | __ src / namespace / MyBundle / resource / view / edit / form.html.twig // front.html.twig extends my problem: -
App.session.flashbag.all front.html.twig in ==> The flashbag is empty -
the app. session.flashbag.all in form.html.twig ==> Flashbag is good and success message So why can not I put the code in front.html.twig ?
I just stumbled on one problem and found it:
If the other subject is not answered your question you can try and dump your flashback to see its structure. By doing so, try adding it to your jogging template:
{% set array = app.session.flashbag.all%} {% dump (array)%} You will know what has happened, at least I have done:
array (1) {["test"] = & gt; Array (1) {[0] = & gt; String (28) "Ceci est un test de flashbag"}} This means that you have messages in your flashback but you can not get the content correctly because it is the second Array my solution:
{% tag, array in line%} {% in line%} for graphing & lt; Div class = "{{tag}}" {{underline}} & lt; / Div & gt; {% Endfor%} {% endfor%} Hope it helps
Comments
Post a Comment