Skip to content


Subversion checkout URL

You can clone with
Download ZIP

Developing DAVE Objects

evantahler edited this page · 2 revisions

Dave Objects

There are two types of classes special to the DAVE API. These classes, DaveTableObject and DaveRowObject may be inherited by your objects to make manipulation with the database as simple as possible.

DaveRowObject are the main object you would use that represent a sigle row within your database. These objects inherit the Delete, Add, Edit, and View methods which will handle database interaction for you, along with whatever new methods you might include.

These classes are defined in API/Objects/_BASE.php Many of these ideas were inspired by the Rails ActiveRecord framework.


A table object is a representation of all of the parameters of a specific mySQL table. This object also contains table-wide methods:

  • status() : Returns status of the Objects ability to link to the database table (should be true when working normally)
  • table() : Returns the name of the table this object is linked to
  • columns() : Returns a list of the columns in the table and if they are required to be unique, null, etc.
  • column_names() : Returns a simple array of just table column names
  • all() : Returns all rows in a table as an array of DaveRowObject(s)
  • count() : Returns the number of rows in the table
  • find() : Returns an array of DaveRowObject(s) which match in input array of matchers

DaveTableObject Example

// setup
$UsersTable = new DaveTableObject("Users");

// counting the users

// all the users
$Users = $UsersTable->all();

// find someone specific
$Evan = $UsersTable->find(array("ScreenName" => "Evan"));


A DaveRowObject is a representation of a single row within a database. A DaveRowObject requires a DaveTableObject to be passed into its constructor. Getters and Setters are available for any table-column attribute for the object. Other methods available include:

  • ADD() : This will attempt to add this new DaveRowObject to the database. Be sure to check for returned messages regarding status. Returns true/false
  • VIEW() : This will load/reload and return the databases values for the objet. Returns true/false
  • Edit() : This will pass the current attributes of the DaveRowObject to the database and attempt to commit. Be sure to check for returned messages regarding status. Edit is the analog of save in other frameworks. Returns true/false
  • DELETE() : This will attempt to delete the row as defined by the current attributes of the DaveRowObject. Returns true/false
  • DATA() : This will return the Object's attributes (not reloading from the database). You can pass an optional array to this method which will contain a list of attributes you wish returned.
  • clean_data() : This method will stip out attributes from the object which are not part of table schema. May be required before ADD() or EDIT().

DaveRowObject Example

The Class (remember, the DAVE methods are inherited)

class User extends DaveRowObject
    public function validate_and_configure_new_user()
        if (strlen($this->DATA["EMail"]) > 0)
            $func_out = validate_EMail($this->DATA["EMail"]);
            if ($func_out != 100){ return $func_out; }

        if (strlen($this->DATA["PhoneNumber"]) > 0)
            list($fun_out, $this->DATA["PhoneNumber"]) = validate_PhoneNumber($this->DATA["PhoneNumber"]);
            if ($func_out != 100){ return $func_out; }

        if (strlen($this->DATA["Password"]) > 0)
            $this->DATA["Salt"] = md5(rand(1,999).(microtime()/rand(1,999)).rand(1,999));
            $this->DATA["PasswordHash"] = md5($this->DATA["Password"].$this->DATA["Salt"]);
            return true;
        else { return "Please provide a Password"; }

Use of the objects

// config
$UsersTable = new DaveTableObject("Users");

// add a new user
$OurUserData = array(
    "FirstName" => "John",
    "LastName" => "Doe",
    "EMail" => "",
    "ScreenName" => "DaveAPI",
    "Password" => "password"
$OurUser = new User($UsersTable, $OurUserData); 

// view user data (from the DB)

// edit that user
$NewUserData = array(
    "ScreenName" => "NewDaveAPI",
    "EMail" => ""
$EditResp = $OurUser->EDIT($NewUserData);

// delete that user
Something went wrong with that request. Please try again.