[nycphp-talk] class design question
Keith Richardson
keithjr at war3.com
Thu Jul 10 19:08:32 EDT 2003
If you wanted to do it with classes, you could have some options for
the saving.
The user could have a save method, that would either look like
$user->save($dbsae); and that would save to the database, or you could
not have a link identifier and just do $user->save(); - or you could
have it write to the database every time it does anything, but that
would be kinda useless. If you were going to have it the most "robust"
code then I would say have a save method, and send it the dbase link
identifier.
If you wanted to have the database a class, you just send it the
database class variable, say $SQLdb, and inside the save(); method, do
something like
$saveresult = $SQLdb->Query($savequery);
so that you can have your own error checking/etc..
VBulletin (www.vbulletin.com) uses a database class variable to do
queries and everything so if you get a chance to look at the source,
that would probabally be most helpful.
Good luck!
Keith Richardson
keithjr at war3.com
www.war3.com
On Thursday, July 10, 2003, at 06:14 PM, David Mintz wrote:
>
> I'm rewriting my PHP/MySQL application that manages the scheduling of
> court interpreters (for our office here in the federal court downtown).
> It's hideous spaghetti and I want to do it over with Smarty and Pear
> and
> OOP.
>
> There are entities like Judge and User and Event and Interpreter that
> will
> merit their own objects and be persisted in the database.
>
> Suppose you have a class User. Would you give it a save() method that
> writes its state to the database? And if so, do you pass this method a
> Pear $db object as argument, or does it already possess its own $db
> object
> (which perhaps you handed it at instantiation time)?
>
> ... OR ...
>
> Would you have write a separate DB class -- one that extends the Pear
> DB
> perhaps -- with methods like saveXXX() for each of your classes?
>
> I hope this is clear. These may seem naive questions to you old pros.
> I'm
> one of those self-taught lightweight dudes and I'd love to get it more
> nearly right this time around. Thanks.
>
>
>
>
>
> ---
> David Mintz
> http://davidmintz.org/
> Email: See http://dmintzweb.com/whitelist.php first!
>
> "You want me to pour the beer, Frank?"
> _______________________________________________
> talk mailing list
> talk at lists.nyphp.org
> http://lists.nyphp.org/mailman/listinfo/talk
More information about the talk
mailing list