The device for my application states that two users will be able to work on the same record of the web app at the same time Without clubbing the data of (unless, of course, they do not modify the same area, then this will be the last one to save the win.) This is a medical system, and it is estimated that the billing people have a record While working on the second section of a tech record Programming has been updated.
Therefore, when a user saves a form, then the system should change the value in the database that the user has actually changed. Because I'm using KPHP, I'm trying to do this in favor of PHP things instead of talking to JavaScript before sending form data about it.
My first thought was to examine the values immediately before saving the database and only changing the values that are not identical. However, if User A has saved the form, then user B has opened it, and then user saves the form B, then changes in User A will overwrite the old data in the User B form.
My next idea was to save the values of the form in the user's session, so when the form opens, the data gets accumulated in the session, and only the value in that session will change in its session. They will be updated in the database. Therefore, in the session $ old_data will be sorted in it.
The problem here is that the user will be unhappy because the user will try to open two records at the same time and then save it. Therefore, I should have session data stored by the record id.
And, it leads me to the last problem. When the user saves the form, then I can unset the data from the session (and then bring it again if they re-present the same record). But, this is not to deal with the situation when the user does not save the form. If they open the form and read it and then go away, then slowly their session is getting filled with debris.
So, when there is a way to clear the trash of the session without erasing the best time and session that they really need a session?
I was ready for a challenge this afternoon, gave it a try - mainly to see that All the logic can be explained in one component, without having to manually code the code from the controller functions.
As a result, some tests have not been used in production (feel free to make changes on GitHub if you find a bug.)
array ('edit'), tell what action to work with); ); Edit Public Function ($ id) {$ record = $ this- & gt; Read (zero, $ id) # did not get found if (! $ Record) {$ this- & gt; cake; Error ('error404'); } # Populate if (! $ This-> Data) {$ this-> Data = $ record; Return; } # Saved form $ saved = $ this- & gt; Model- & gt; Save ($ this-> Data); If (! $ Saved) {$ this- & gt; Session-> Set flash ('failed validation'); Return; } #Trusting $ this-> Session-> Set Flash ('Saved fields' are saved); $ This- & gt; Redire (array ('action' => gt; 'index')); }} During the operation of the Administrator ( Model Controller :: Edit () in the above example), $ this-> Data Populate the form using . The action will take place after the controller and in the session $ this-> Data will be saved to . OK, until the verification has failed, as long as we are working with the user submitted data at that time. When the components come in new requests, before the operation of the controller, and clears any unchanged data $ this- & gt; Data (by comparing it with session), which means that it should satisfy your needs (only converted field) and ready to save. Note: I have my SaveDiffComponent :: extractChanges () method is not working properly, but I would have left it for you. Be sure to use debbakit during testing (session and variable tabs) and remember that you need to refresh twice to see the new session data (since the next request can not read PHP new session data. Or something like that)
Comments
Post a Comment