Re: FormBuilder process callback

From: Date: Wed, 09 Nov 2005 15:04:17 +0000
Subject: Re: FormBuilder process callback
References: 1 2 3 4  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-21858@lists.php.net to get a copy of this message
Yep i have overloaded before, thats what i am kinda doing, however i think ive been mistaken for some prcocess method which inserts/updates and deletes for you, in particular delete which traps the press of a delete etc, i have to set all this up manually ie if ($_POST['delete']) { $do->delete(); } etc .. On 10/11/2005, at 1:38 AM, Brett Bieber wrote:
Hey Dan, On 11/9/05, Dan Rossi <pear@electroteque.org> wrote:
Hi there I was wondering what the callback method for FormBuilder
is
to prcoess the posted data and handle updating the dataobjects etc, i
am
needing it to somehow cascade update aswell as cascade delete
joined
table records somehow, as sadly the machine this system will be running on is mysql 3 and i cant just setup a cascade delete. Let me know.
Instead of using the callbacks for FormBuilder, I would overload the insert() update() and delete() functions for the DataObject. There is an example that outlines overloading these functions for doing extra data handling. http://opensource.21st.de/25.html#A10 On that page you can find some examples and it shouldn't be hard to imagine where you could add in code to grab the extra records and cascade delete or update them. In effect, you're capturing the call to the delete() function and doing your extra data management before you handle the deletion of the record. In some pseudocode: delete() {
     // Before I delete this record, grab others
     $child_recs = DB_DataObject::factory('linkedtable');
     $child_recs->foreign_key = $this->key;
     if ($child_recs->find()) {
         while ($child_recs->find()) {
             // do extra processing if necessary
             $child_recs->delete();
         }
     }
     return parent::delete();
} Or alternatively you could just run a SQL DELETE WHERE foreign_key=$this->key statement and delete them all at once if you don't need additional processing for each record. Hope that helps. -- -Brett http:saltybeagle.com aim:ianswerq


« previous php.pear.general (#21858) next »