Re: Using DB_DataOjbect and Quickform together
| From: | Jeroen Houben | Date: | Thu, 06 Mar 2003 14:33:00 +0000 |
| Subject: | Re: Using DB_DataOjbect and Quickform together | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-4064@lists.php.net to get a copy of this message | ||
Demian Turner wrote:
Hi, I'm trying to integrate Quickform and DB_DataOjbect for a simple UserManager, the problem is how to feed a DB_DataOjbect object to the setDefaults() method in Quickform, so the form can be pre-populated. The form is setup so all the attributes are elements of the array 'user':Hi, At the moment I'm using the following code, but it's a quick and dirty hack, which only works for simple stuff so I'd also like to see a proper method for this in QuickForm: foreach (get_object_vars($dataobject) as $var => $value) {user[username] user[password], etcso the whole user entity can be cast to an object easily$oUser = (object)$_POST['user']Any DB_DataOjbect will know this is very handy for updating entities:$modUser->setFrom($oUser);The problem I'm having is that a major transform of the entity is necessary to get it into a format compantible with QF. Apologies in advance for the following code, there's probably an easier way of doing this ;-)
if (substr($var, 0, 1) != '_') {
$DEFAULTS[$var] = $value;
}
}
$form->setDefaults($DEFAULTS);
This just takes all the public properties of the object and puts them in the $DEFAULTS array.
- Jeroen