design pattern/code generators

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux