How to update an item in CakePHP

Example: Site Explanation:


  • Two super administrators SA1 SA2
  • An update button will appear on the control panel when they enter the admin panel.

Is required


When SA1 clicks the Refresh button, it will take 15 minutes to complete the task. Consider while the process is in progress, & SA2 is logged in, it should find out SA1 has already pressed the refresh button until it is finished, SA2 will not be able to click on it.


What I've done


Created table 'button_status' [id, status (' complete ',' uncomplete ')] every time SA1 or SA2 clicks the update button, I insert a new record with status as'incomplete' until I show the process in which to load the image and disable the update button for SA1 and SA2, as soon as the process receives the end after 10 coins. I am updating the status for the last entry to complete. and deleting the downloaded image and turning on the refresh button.
Everything works fine, the problem is loading the image or the disabled button for other admin who didn’t click the refresh button, I can’t delete it, because for this I need to refresh the page. Is there a way to show completion automatically when for another administrator without refreshing the page after the “full” status updated in db?

+4
source share
1 answer

There are three ways to get it straight.

Ajax comet

This includes a client-server implementation where the client responds to events on the server. Learn more about AJAX Comet . One of the solutions I used is a meteorite server . It was relatively easy to configure, but you need an access server to configure it in your own way. However, it was discontinued.

Arguments

  • You only refresh the page when there is a change. Thus removing the load on your server.
  • Little or no delay

vs

  • Client Server Configuration
  • Long run

Temporary survey

You can poll your server once during a period of time for changes. You are requesting a custom script to return locked records in JSON or XML. Based on this, you update the button status using javascript. More details are discussed. Refresh AJAX data every X minutes / seconds, jQuery

Arguments

  • Simple and fast implementation

vs

  • Adds extra load to the server
  • Still has some waiting time

Leave it as is

If this is the administrative interface and disappointment when clicking on an already locked record, it does not matter much, I would leave it as it is.

One more

I found an interesting solution for applications with live data http://meteor.com/ , their tag, but currently they only support mongodb.

+1
source

Source: https://habr.com/ru/post/1485749/


All Articles