DariusVE DariusVE - 1 year ago 74
PHP Question

Interactive file processing in using PHP, jQuery and Ajax

I'm migrating an old MS-DOS Foxpro program to cakePHP, but in some part of the application process the user will have the possibility to load a text file and process it according to some business logic.

I worked the algorithm, and it's working fine, I programmed it in plain PHP.

But in some parts of the process the user must interact performing some tasks, in plain PHP it's possible to do it.

My question is:

How can I have an interactive file process on a MVC framework, since the controller had processed the data when it`s give the control to the view.?

jQuery-ajax could help?

What do you think?



See my answer below

Answer Source

What @AD7six told you is completely right however your question is very vague.

What you seem to need is to provide an interactive (realtime?) way for a user to edit data after a files has been uploaded and processed?. If it is 'data arranged in rows' I can suggest some DataGrid - imagine this as a Web representation of your file's structure.

What you're trying to say with 'the view shows the result of a method or action on the controller' is that this case is in the normal HTTP (with MVC) flow:

Browser (user) initiates a request => Request is processed my Controller => Model is called (gets, saves or manipulates data) => Data is returned to Controller => Controller handles the data over to the View layer => The view layer renders, Controller returns the Response (the rendered view)

In order to do this thing interactively you will have to use AJAX (I propose AJAJ).

The overall paradigm in this case is that the above flow is iterated on every AJAX request. You can achieve this in many ways:

  • Use plain JavaScript and XMLHttpRequest
  • Use jQuery's XMLHttpRequest wrapper functions ($.ajax(), $.post(), $.get(), $.load(), etc.)
  • Some other JS lib's AJAX capabilities (MooTools for example)
  • Use an real-time JS app framework

This also heavily depends on the browsers (and versions) you need to support. You will need to provide 'access' for the client-side via a controller or a full API. The best solution for an API would be REST. If this is an enterprise app I suggest you adhere to the Richardson Maturity Model.

If you don't need a fully-realtime app I'd go with jQuery AJAX or some other JS lib's AJAX. The thing is that what you request as an answer is an overall explanation and that is why I am not going to provide code examples. Cake has JSON views that you can use to return data. The other option is an empty layout and a view that returns JSON encoded data like:

<?php echo json_encode($data);?>

Hope this helps. If anything ask.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download