php - Forms and success output -


Good,

This is an initial question, but I do not know what's the best way. I have a basic CRUD (create, retrieve, update and delete) my project and if I succeed or in some div some messages within the same message Want to output page?

So, basically, I have a form that takes action on the same page and I have an div #statusDiv below this form that I have to output Want to Register with success in the register

What is the best way to do this?

  • Set a flag in the controller $ it-> View- & gt; Flagstats = 'message' then it's called in view?

Just to make it more clear this is my code:

  // IndexController.php indexAction () ... // Check whether If the data is deposited ($ this-> getRequest () -> isPost ()) {... $ registries- & gt; Insert ($ data); $ This- & gt; View- & gt; FlagStatus = 'message'; }  

Then my view:

  .... & lt ?? Php if ($ this-> flag state) {? & Gt; & Lt; Div id = "divStatus" class = "success period -5" style = "display: none;" & Gt; & Lt ;? Php echo $ this- & gt; Flag position; ? & Gt; & Lt; / Div & gt; & Lt ;? Php}? & Gt;  

In this situation, you are redirecting, $ the- > View-> Flipstats will be lost. Instead, you should use Flash Messenger Action Helper:

Basically you use it as you are currently, except you can:

  $ this-> View- & gt; Flag status = 'message';  

to

  $ this-> _helper-> Flash Messenger- & gt; Ad message ('message');  

After this, you will need to send the flash messenger object to view. You should do this at a place that is executed on the request of every page so that you can send messages to any page:

  $ this-> view-> gt; Flashmessenger = $ this- & gt; _helper - & gt; Flashmessenger;  

and then change your view:

   Flash Messenger-> Hermes ():? & Gt; div id = "divStatus" class = "success period -5" style = "display: none;" & Gt; & lt ;? php $ message = $ this- & gt; Flash messenger- & gt; get message () ;; & gt; & lt ;; php foreach ($ message as $ message):? & Gt ; 

$ Message ;? & gt; & lt; / p & gt; & lt ;? php endforeach ;? & gt; & lt; / div & gt; & lt; ? Php endif;? & Gt;

Hope this helps!


Comments