View Single Post
Old 01-22-2005, 09:12 AM   #2 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Cool stuff. Looks similar to some of the db object structure I use in an old framework. Basically each table has a class that inserts and retrieves data. From there I define the fields I want to retrieve in an array (which isn't necessary, but I don't always like to fetch every field for every call)

A basic class would be like:

PHP Code:
class foo extends fooModule {
  var 
$assign_vars = array(
      
'foo_id''foo_name''foo_this',
   );

   class 
foo($id=0) {
      
$par get_parent_class($this);
      
$this->$par();

      if (
$id) {
         
$this->_get($id);
      }

   }

   class 
_foo() {
      
// destruction
      
return;
   }

// other public methods go here
//

   // {{{ _get()
   
function _get($id)
   {
      
$db newObject('fooModule::Db');
      
$q  = <<<EOQ
         SELECT *
         FROM 
{$this->t['TBL_FOO']}
         WHERE foo_id = '
{$id}'
EOQ;

      
$db->query($q);
      
$db->next_record();
      
$this->_assign($db->Record);
   }
   
// }}}


So then I can grab an object pretty quickly and/or create other functions that search and return an array of objects.

PHP Code:

$obj 
newObject('Module::foo'$id);

or
$results $obj->getActiveFoo();

foreach (
$results as $k => $v) {
   echo 
$v->foo_id;
   
//etc.


I'm still looking for a new framework to use and pear's DB and DB_DataObject look pretty cool. (especially dataobject - you just describe the data and tell it what kinds of things you want to do in you code.. no manual SQL flipping)

-r
idx is offline   Reply With Quote