Created
October 19, 2009 02:05
-
-
Save minichate/213026 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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