Re: DB_DataObject: check for defined variables in auto-generated classes
| From: | Justin Patrin | Date: | Fri, 03 Sep 2004 15:47:30 +0000 |
| Subject: | Re: DB_DataObject: check for defined variables in auto-generated classes | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-14394@lists.php.net to get a copy of this message | ||
On Fri, 3 Sep 2004 16:02:58 +0200 (MEST), Thomas Mammitzsch
<smartt@gmx.de> wrote:
> hi all,
>
> i try to set variables in autogenerated classes by using a forech statement
> like this, cause this would shorten my code a lot:
>
> $new_reise = DataObject::factory('Reisen');
>
> foreach($_POST as $key => $value)
> {
> if(isset($new_reise->$key))
> {
> $new_reise->$key = $value;
> }
> }
>
> but the isset() function doesnt work because the variables have no values by
> default (null). is there a way to check if the variable exist because i dont
> want to modify the auto generated code by hand. Or maybe i can set an empty
> value to the variables when autogenerating somehow?
>
> regards, Thomas
>
Use something like this:
foreach (get_class_vars(get_class($new_reise)) as $var => $val) {
if (isset($_POST[$var])) {
$new_reise->$var = $_POST[$var];
}
}
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--