Re: DB_FormBuilder
| From: | David Thunman | Date: | Thu, 18 Mar 2004 17:43:51 +0000 |
| Subject: | Re: DB_FormBuilder | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-11378@lists.php.net to get a copy of this message | ||
Hi Markus,
Thank you for your extensive explanation. I just figured out to pass my FormBuilder by reference when creating the form object, and it was the solution to that problem. However, The main issue lays in the situation where I process and display the form on the same page and I had problems to have the newly updated data displayed right after a successful FormProcess call. What I have done is to create a new form object before calling form->display. Then i dont have to worry about updating the current objects primary key.
When it comes to the related table problem, I have one main table with the textdata, one table with the uploaded file data (where files can be of any type), and one table with only an id to the main table, an id to the file table and some additional data. I need to have my file data separated in cases where several main items will share the same file and then not having to upload a duplicate file.
I think doing the work as you suggested in the postProcess() will do.
Thank you,
David Thunman
On 2004-03-18, at 17.10, Markus Wolff wrote:
David Thunman schrieb:The flow is so that each item in table "measure" will have a file form field where I want to upload a file and then insert the file data into the "file" table. Then I use the "photos" table for the relation between the "measure" and "file" table. The problem is how to implement this in my FormBuilder Measure Class when I create the form. Is it possible for the FormBuilder to recognize such a relation from within the Measure Class, or do I have to create an instance of the File Class in the Measure Class. Sorry for this confusion, but I am a bit stuck here.This is a classic n:n relation, which is not handled by FormBuilder automatically. If all action goes from the measure class, your best bet is to implement a postProcess() method in which you fetch the information from the file field, make a new instance of the file class, insert a new record there, take the ID of your freshly-inserted measure record, make an instance of the photo class, put the new file_id and measure_id inside, and do an insert(). Careful: postProcess() is always triggered after processing the form data. Thus, it will not only be executed after an insert() operation, but also after an update() - so it's up to you to find out what kind of operation you're dealing with and act accordingly! That should to the trick, at least if I have understood you correctly... :-) But: This will actually make a new entry in the file _and_ photo table each time you make a new measure record. So basically, you're creating a 1:n relationship here and there's no need for a third table. From a user interface point of view it would be clearer (and also easier to code) to first let the user create a new measure record and then give him the possibility to add an arbitrary number of files (using a dedicated file upload form) to that existing record - you can then implement the postProcess() method in the file class, using the measure_id from the existin record... and then you'd have a true n:n relationship. Regards, Markus