[thelist] php design question
David U.
davidu at everydns.net
Mon Nov 18 16:14:01 CST 2002
Tom Dell'Aringa wrote:
> I'm building an application that is going to reuse a fair amount of
> code. I'm wondering if a) its bad form to have an include within an
> include, and b) if I should be using an include for the get item as I
> am doing below - see code:
Two words; objects and classes. (see below)
> I want to make this whole code block an include, because there will
> be several pages where I pull the menu item. Does this make sense?,
> and see the nested include...
Try using a different paradigm; objects and classes. For example, you could
do:
In your page:
list($item, $description, $price, $category) = $database->getMenuItem($id);
And then in your databaseObject class you have some method called
getMenuItem which does something like this:
function getMenuItem($id) {
$result = $this->_db->getRow('Select * from menuitem where menuitemID =
' . $id, DB_FETCHMODE_ASSOC);
if ($this->_db->isError($result) {
die("Bork! There is no MenuItemID $id");
}
return $result;
}
Using Pear::DB and some simple helper classes can help you write clean,
reusable, flexible code.
-davidu
More information about the thelist
mailing list