Re: Questions on extending DataObject

From: Date: Sat, 05 Jul 2003 02:39:15 +0000
Subject: Re: Questions on extending DataObject
References: 1  Groups: php.pear.general php.pear.general 
Request: Send a blank email to pear-general+get-6491@lists.php.net to get a copy of this message
Markus Wolff wrote:
Hi there, whoah, this package is really great - I´ve decided to kick out our own implementations and use DataObject exclusively from now on ;-) As I like to be able to habe running prototypes for applications rather quickly, I´ve begun to write a class that extends DB_DataObject and contains additional utility methods, the first being a method called getForm() that tries to automatically build a HTML_QuickForm object from the DataObject´s properties. In the process of doing that, I´ve run into some trouble though: If the DataObject has links to other tables, I want to add a selectbox to the form that contains all possible entries of the linked table to choose from (I know this is risky, I´m gonna make this configurable later on). To find out if there are any links, I wanted to use the getLinks() method like this: if ($this->getLinks()==true) {
    // Do something with that information
}
yeap - at present getLinks doesnt return anything.. - have changed it to return true on success (you can also alter the format by using $this->getLinks('link_%s'); now.
Unfortunately, getLinks() always returns false and never fetches the linked data. I'm not sure why it shouldnt return data .. - have you tested with debuglevel(1)
To find out if it´s just the link.ini that has wrong definitions, I then tried it with $this->getLink('linked_field_id') and it worked like a charm, so I assume my link.ini must be correct. Is there another method that allows to just check if a specific field actually *is supposed* to have links, without trying to retrieve them?
not at present, - you would have to play with $_DB_DATAOBJECT['LINKS'][$this->_database][$table] you may want to look at getLinkArray() - from what I remember it deals with 1=>many to some degree. I think some of the API of that is a little messy.. something simple like $link = $dataobject->getLinkObject('rowname'); $links = $dataobject->getLinkObjects('rowname'); // which builds the querey (where N:1 fetchs and 1:N only builds the base ready to find - only snag is links.ini does not understand 1:1) would provide a more flexible solution.. - leaving the implementation up to the user more..
That would be perfect for my needs. If there´s not, how would I need to proceed to write such a thing? Are the link informations stored in some config variables somewhere? Another problem: I have added these config settings to my DataObject.ini ... extends_location = DB/DataObjectOnSpeed.php extends = DB_DataObjectOnSpeed When the classes are generated, the "extends" section is correctly rewritten to "DB_DataObjectOnSpeed". The require_once() statement, however, remains untouched and still points to "DB/DataObject.php", so I have to do an additional search & replace after the class generation.
in principle, the generator replaces everything between ###START ... ##END_AUTOCODE I've hacked in support to modify the class AAAA extends BBBB \n{ but havent done it for require_once ... - to do this, it would need to have an idea of what to replace from.. (eg. look for 'DB/DataObject.php') .. or if you changed your base class from something else.. .... If you want to do a patch to add an ini option for extends_location_replace_from = DB/DataObject.php I'll add it to the genreator look at the regex at the end of $generator->_generateClassTable() Regards Alan
Thanks in advance for any insight on these topics. Regards, Markus


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