• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making sure a record hasn't changed

To get the preliminaries out of the way...
1) I'm new to PHP.
2) I'm new to CI.
3) I'm new to database development.
4) I've been programming for decades.
5) I'm working on a site that's heavily database driven and the design's been worked out with someone who knows DB well.

Ok. The problem I'm having is likely due to ignorance about CI or PHP (and maybe a little SQL) so if after I get to describing the problem you can point me to some links for additional reading that would be fine. Reading doesn't scare me, I just haven't found what I think I need when searching here or the rest of the Intertubes.

I've gotten far enough with the site that a single user can go through and add stories which are composed of paragraphs and finally sentences (not really but this is a simpler analogy).

What I want now is to verify that when editing any of the three elements that some other user hasn't already modified the record.

I've got a controller function that looks something like:

function editstory($story)
set up all the $data for the view
*** get the last update time for $story
Set the form validation rules
if form_validation_run == false
re-load this view, passing in $data
check the update times, make sure they're the same
reload the view if they aren't

The problem is that the form submit calls editstory (which is the pattern I've seen in all the samples and docs so far) which sets up all the data again before running the validation, blowing away the data I'd saved last time.

Does this make sense? What am I missing here?


You can read into this : http://ellislab.com/codeigniter/user-gui...ation.html,

this might help.


Unfortunately no, those samples don't cover persisting data between refreshes of the page.

I'm new to web programming so it seems like the wrong way to go but I was able to do what I wanted by saving the update information in session data.

So either nobody is using the forum right now or that was the right answer? :-)

Is there a better way other than using up precious session memory? Or is it just not that precious?


A couple options:

1) Store the last updated time in a session variable as you already suggested. If you are using the database to store session data, it is far from precious. Smile

2) Store the last updated time in a hidden input field. Upon success and pending save, retrieve the DB's time again and compare the two.

I'd recommend the session data since it's far harder to be manipulated (even though manipulating the form input would cause it to be rejected anyway).

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.