Tuesday, 15 July 2014

symfony - Symfony2 - PostFlush Event -


I have a set of things that you can add a warning to your database through a form. When this alert was added, a post flush event took a warning and did one thing for it. It all worked perfectly.

I have changed things now. Instead of adding an alert through a form, I can display all the possible alerts that they can do.

The problem now is that in my controller, a warning is added using a precursor

  foreach (Dollar data as $ flight = & gt; $ seat) {$ alert = new alert (); $ Alert-> SetLastUpdated (); $ Alert-> SetIsDeleted (0); $ Alert-> SetAlertStatus ('active'); $ Flight number = new flight number (); $ FlightNumber- & gt; SetAvailabilityAlert ($ warning); $ FlightNumber- & gt; SetFlightNumber ($ flightNum); $ Alert-> AddFlightNumber ($ flightNumber); $ Em- & gt; Continues ($ flightNumber); $ Em- & gt; Continues ($ warning); $ Em- & gt; Flush (); }  

The problem with this is that my post flush is executed only for the first alert that has been added. So if I select three alerts, then an additional post flush action is taken, but the other two do not.

I have tried to use an array with my postflush instead, although it does not seem to work

  class warning listener {secure $ api_service; Protected $ alertEntity = array (); Safe $ em = null; Public function __ composition (UapiService $ api_service) {$ this- & gt; Api_service = $ api_service; } Public Function Postpartist (Life Size Aventorgs $ Algés) {$ entity = $ args- & gt; GetEntity (); If ($ unit example alert) {array_push ($ this->; alert, $ unit); Var_dump ("test"); }} Public Function postFlush (PostFlushEventArgs $ args) {$ this- & gt; Em = $ args- & gt; GetEntityManager (); $ EventManager = $ this- & gt; Em- & gt; GetEventManager (); $ EventManager- & gt; Remove documentant listener ('postflush', $ this); \ Theory \ Common \ util \ debug :: dump ($ this-> alertEntity); If (! - (- $ -> this-> cautionary warnings)) {foreach ($ this-> warning sign as $ alert) {$ this- & gt; API_service- & gt; AddFlightsAction ($ warning); The interesting thing is that var_dump outputs twice if I select 2 alerts, which will leave me to believe that the correct numbers are added to the array. 

However, the Symfony2 dump of the object only outputs an alert, so apparently not. The interesting thing is that if I dump the array in the postpartist function, then I get the load of the listed alerts. If I dump into the post flush function, there is only one alert output.

How do I manage multiple alerts here?

Firstly you should not flush the loop, To flush out, then get an array of alerts from PostFlushEventArgs in your Postflush event, then use whatever you want them to.


No comments:

Post a Comment