Skip to content

Instantly share code, notes, and snippets.

@minichate
Created October 19, 2009 02:05
Show Gist options
  • Save minichate/213026 to your computer and use it in GitHub Desktop.
Save minichate/213026 to your computer and use it in GitHub Desktop.
<?php
class AddressEntry extends DBRow {
public function createTable() {
/* Create a model definition and map field types to db column names and labels.
* ex: DBColumn::make('text', 'first_name', 'First Name') means:
* - field is a 'text' field
* - field maps to the column 'first_name' in database
* - field should have the label 'First Name' when being displayed in a form
*/
$cols = array(
'id?',
DBColumn::make('text', 'first_name', 'First Name'),
DBColumn::make('text', 'last_name', 'Last Name'),
DBColumn::make('text', 'phone', 'Phone Number'),
);
// This model belongs to the "addressbook" table
return new DBTable('addressbook', __CLASS__, $cols);
}
/* Get all rows in the table, or filter on a query:
* ex: AddressBook::getAll();
* AddressBook::getAll('where first_name="Chris"');
*/
static function getAll() {
$args = func_get_args();
array_unshift($args, __CLASS__);
return call_user_func_array(array('DBRow', 'getAllRows'), $args);
}
/* Get a count of the number of objects that will be returned on a query.
*/
static function countAll() {
$args = func_get_args();
array_unshift($args, __CLASS__);
return call_user_func_array(array('DBRow', 'getCountRows'), $args);
}
/* Prefix all form fields with this string to prevent namespacing issues
*/
function quickformPrefix() {return 'addressbook_entry_';}
}
DBRow::init('AddressEntry');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment