Page 1 of 1

automatic edit

Posted: Wed Apr 08, 2009 6:34 pm
by networkguy
Using oop php 5 approach, with two classes, one class: Book class and the other class: Page class.The Book class keeps an updated array of Page objects, as it is composed of them.

If say I added a new Page (through the Book object) object properties to the database using save() method from the Page class, how would I go about automatically enabling "edit" bit to be set on the last save. So what I mean from a logical standpoint, the last saved page object property "text" can be changed/edited until the next saved object (ie: the one on top of the stack).

All I want to do is edit the "text" field basically (yes, I definitely need to use UPDATE mysql query). Do I check the most recent element in the array of Page objects and allow for save or edit? What I'm really asking is, how do I keep track of it. Do I declare a bool and set the most recent to 1 (for edit) and the one before to 0?

Another user here proposed a related solution on a different thread, but I'm having a bit trouble seeing how to adapt that code to this since I am a newbie at oop. I will try and utilize what the other user has suggested, but to prevent me from having to struggle the way through I need some more ideas.

Thanks to anyone in advance!

(wasn't sure whether to put this in Theory and Design or PHP Code)