/** * This is a development function only designed to help you build optimized dbrecord objects. * It is designed to be executed from a developer console and should never be used in actual code * * Syntax: DBRecord::BuildDefaults('tablename'); * Result: Outputs PHP code for pre-defining the column names and primary keys for the table your model accesses. * Copy and paste the resulting code into your model's class declaration. * * @param string $tablename Name of the database table the model is created for. * @return void */ public function BuildDefaults($tablename) { if (!$tablename) { throw new Exception("Can not build defaults: Missing table name.", E_USER_ERROR); } $o = new self(); $o->tablename = $tablename; $o->_loadKeys(); echo "<pre>"; echo 'var $tablename = ' . "'{$tablename}';\n"; $ar = array(); foreach ($o->primary as $key) { $ar[] = "'{$key}'"; } echo 'var $primary = array(', "\n\t", implode(",\n\t", $ar), "\n);\n"; if ($o->auto_increment_field) { echo 'var $auto_increment_field = ' . "'{$o->auto_increment_field}';\n"; } $ar = array(); foreach ($o->keys as $key => $value) { $ar[] = "'{$key}'=>'{$value}'"; } echo 'var $keys = array(', "\n\t", implode(",\n\t", $ar), "\n);\n"; echo "</pre>"; }