Re: DBDataObject Nubee

From: Date: Tue, 13 Jul 2004 05:50:46 +0000
Subject: Re: DBDataObject Nubee
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-13670@lists.php.net to get a copy of this message
On Mon, 12 Jul 2004 17:00:46 -0700, Don Fitzsimmons <dfitzsimmons@cox.net> wrote: > I am using DB_DataObject for the first time and I am in love. As with > any worthwhile, lasting relationship, I can see this one is going to > require some serious commitment and patience. I am trying to use a > method to execute a DBDO query and I want to be able to access the > object that it returns but I don't quite get what this baby is > returning. Here's my code; > Where do I begin...;-) > The "factory" class: > > class UserDBServices > { > > function authenticate($userName, $userPass) > { > $user = new DataObjects_Users(); You should really be using DB_DataObject::factory() here as it will auto-load the class file for you: $user = DB_DataObject::factory('users'); > $user->password = $userPass; > $user->username = $userName; > $user->find(); > > //create a new User object upon successful login > if($user != null) { $user can't be null as it is an object (you already created it above). You may want to look into some PHP OO tutorials for the basics. What you really want here is: if($user->find()) { find() returns the # of records found. > $user->fetch(); > return $user; > }else{ > $_SESSION['loginError'] = 'loginError'; > header('location:'.LOGIN_FORM_VIEW); > exit; > } > } > } > > The implementation: > > $person = new UserDBServices(); > $person->authenticate('joeuser', 'letmein'); > > echo $person->first_name; > echo $person->last_name; > You're returning $user in the code above, so you should be doing: $user = $person->authenticate('joeuser', 'letmein'); echo $user->first_name; You could also set $user as a member var in that authenticate function: $this->user = DB_DataObject::factory('users'); Then, when out of the function: $person->user->first_name; > This does not work the way I'm trying to use it here, but this is what > I want it to do. Can anyone help me understand how to access the values > that DBDO returns? > -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin--

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