NYCPHP Meetup

[nycphp-talk] Object Oriented Question

Adam adam at ecamp.net
Fri Jun 7 11:07:16 EDT 2002


I generally use php classes for all my code, but mostly centered around
an OO design from the UI and second logic, especially for pages like
your.

I would have a class gamesite  with all my base functions that would be
use. User authentication, emails, voting functions etc... and if you
don't have that many feature you can keep everything in this one class.
Or if you have multiple sections, you can create different classes that
extend this one to keep things separate and neat.

So you can have something like in index.php
Include "gamesite.class";
$page=new gamesite;
$page->init(); //start session, whatever else u do every page
$page->checkLogin(); // checks to see if user is logged in, if not
redirect somewhere
$page->buildTop(); //builds top nav
$page->processForms(); //process any forms that may have been submitted
before displaying content
$page->showGameReview();  // here you can do that example you were
talking about
$page->footer();

and then inside class gamesite, you can build functions that these
master functions call... but this generally keeps things a little more
organized than complete top down programming I suppose.  PHP isn't C++
or Python, where it takes a lot more effort in some cases to really OO
something.

I find having a few base classes is nice and I just extend upon them,
using functions I've had for years as if they are native php I'm so used
to them.

If you check out http://madhive.com  it was done all PHP OO over the
past few years.  Site is a bit slow most likely because of lack of
attention to the servers for months.  The you login and notice the
content boxes on the right, those are all treated as separate php
objects throughout the users session and move from page to page.  Their
functionality is nicer throughout the site.  As well as skin color
changes, and other preferences. The OO method made changing these things
super easy.

-----Original Message-----
From: ophir prusak [mailto:prutwo at onebox.com] 
Sent: Friday, June 07, 2002 10:48 AM
To: NYPHP Talk
Subject: [nycphp-talk] Object Oriented Question


Hi All,

I've decided to clean up the code on my site, and at the same time use
object oriented code.
I have a few ideas in my head, but I really wanted to get some input
from others that have built projects in PHP using OO code.

Here's the problem I'm currently trying to solve (I've simplified it
a bit and left out un-necessary details).
My site is a video game site. Currently, my database has:
A games table which has basic game information for each game (game_id,
title, console, etc)
A reviews table which has game_id (foreign key to games table), review
date, review text, reviewer name and email.

If you look at this URL
http://ps2.consolemonkey.com/reviews_date.php3?order=rev_id 
you can see a page which shows a list of all the games and the date for
the most recent review for that game.

Currently I'm just doing this with a single SQL query (simple join of
the two tables) and echoing out the results.
Very fast.

I'm trying to envision how to create this page using object oriented
code.
My initial thought was to somehow use a game object, but if I have to
instantiate a game object for every game, this seems like it would have
an enormous amount of overhead and be slow.

How is this usually done on OO projects ?

Am I missing something or would you say that if your data sits in a
relational
database and your doing a search or mass listing of data then OO code
is not the way to go.

comments/suggestions/thoughts/ideas/etc ?

Thanx
Ophir 

 
----
Ophir Prusak
Internet developer 
prutwo at onebox.com | http://www.prusak.com/ 

 





More information about the talk mailing list