Re: Reusing DB_DataObject

From: Date: Fri, 30 Sep 2005 09:27:52 +0000
Subject: Re: Reusing DB_DataObject
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-39977@lists.php.net to get a copy of this message
Yes, I think you have to clone the object just before the find or to create a new object (with the factory) in order to have an "empty" dataobject. --- I see, a lot of people is interesting in Dataobject, I use it since one year, it's a great package ! --- I did the same thing as you for a CMS: - generate listing in a web page (like you) but with no form : a button to add record and edit link for all record in the listing. - edit page have a quickform, the page take an ID in get parameter : with no ID, the form is blank to add a new record, with an ID it is use to edit one of the record (I have a link in the listing for all records) Jocke Selin a écrit :
On 9/30/05, "Sylvain > Com-Océan" <sylvain.comocean@gmail.com> wrote:
I think (if I understand your problem correctly) that you have to use the clone function in your fetch() like : I often make listing of dataobject by using : $obj->find(); while ($obj->fetch()) { $obj_array[]=clone($obj); } The array contain the same object if I don't use clone function (because of the Reference).
Sylvain, thanks for your reply. I played with your suggestion, and as I feared, it doesn't help. The thing is that I'm doing the loop _before_ creating the form. Which means that the calls to find() and fetch() will remain valid when I pass the object to the form. My guess is that I need to clone() the object before the calls to find() and fetch()...? I haven't tried but I'm guessing that would work; however: Is this the "right way" of doing it or is there some shaolin-kung-fu-secret that I'm not aware of? Thanks! /Jocke


« previous php.pear.dev (#39977) next »