Reply to design pattern/code generators

Your name:

Reply:


Posted by Robert Mena on 01/30/05 03:17

Hi All,

I am looking for advice regarding design patterns/code generation in PHP5.

I have a simple code generation tool (written in PHP) to interface with
database. It works fine for simple situations but seems a little
"strange" for more complex ones.

Suppose I have a table user (id, name, age) and a table
account(idAccount, idUser, name). My generator creates a class for each
table and a standard db class. Each class basically has a set/get
method for each property and some "standard" insert, delete, update,
search methods

ex.
class user
{
var $db
function setName(..)
function getName()
function insert()
{
$this->db->query("insert into user values...")
}
....
}

I've omited the other methods/constructor but you can get the picture.

The problem comes when I have to access information the comes from 2+
tables. Suppose I have to show all users accounts. Now I end up with
something like this.

$u = new User() ;
$a = new Account() ;
if($u->search())
{
for($i=0;$i<...)
{
$idUser = $u->getId() ; $u->next() ;
$a->setIdUser($idUser) ;
if($a->search())
{
// print
}
}

While this works I feel there must be an easier/cleaner way. If I was just
querying the database a join would give me the result in one pass.

In my case what should I do ? create a new method "showAccounts" ?
Where should I put it, in User or Account class ?

I am interested in advices regarding how to design it better so I can
make the proper adjustments in my generator.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация